用函数生成href


Generating href with a function

我正在尝试写一个自定义的WordPress主题。

我把它放在我的header.php:

  <h1>Roux Academy of Art and Design
        <a href="<?php echo siteRoot('Blog'); ?>index.htm" title="home"></a>
    </h1>

我希望h1内的链接指向index.html,但是当我在href内添加PHP位时,一切都消失了,我得到一个空白页。

我的functions.php:

<?php
    function siteRoot($theFolder) {
        $home = get_home_url();
        // strpos(string, substring)
        $thePosition = strpos($home,$theFolder);
        // substr (string, start, length)
        $thePath = substr($home, 0, $thePosition);
        return $thePath;
    }
?>

有什么问题吗?

我在header.php中尝试了这段代码,但仍然不起作用

<h1>Roux Academy of Art and Design<a href="
<?php echo esc_url( home_url( '../../../Blog/roux_academy/index.html' ) ); ?>

为什么不这样呢?

<h1>Roux Academy of Art and Design
    <a href="<?php home_url(); ?>/index.htm" title="home"></a>
</h1>

使用home_url(),或者在这种情况下,您只能在没有任何PHP代码的情况下这样做:

 <h1>Roux Academy of Art and Design
        <a href="/index.htm" title="home"></a>
    </h1

当我像这样添加页面路径时

<h1>Roux Academy of Art and Design<a href="
<?php echo esc_url( home_url( '/Blog/roux_academy/' ) ); ?>
index.html" title="home"></a></h1>