【问题标题】:Header how to modify title of the page "on the fly"标题如何“即时”修改页面的标题
【发布时间】:2010-05-13 09:45:55
【问题描述】:

我的标题在每一页上都被称为你可以想象的。

这意味着在每个页面上我都有相同的标题(对 SEO 不利)

有没有办法在 header.php 之外设置页面标题?

谢谢

【问题讨论】:

  • 最好看一些示例代码来了解您的文件的结构,否则您会得到更通用的答案。

标签: php header title


【解决方案1】:

创建一个变量$page_title。在包含标题之前设置它,并且在标题中有类似的内容:

echo("<title>$page_title</title>");

【讨论】:

  • 谢谢你这么快 ;) $header = "我的页面标题"; include_once 'header.php'; header // echo ("$header");
【解决方案2】:

在包含标题之前为标题设置一个变量,然后在标题中输出变量。

【讨论】:

    【解决方案3】:
    include ('includes/header.php');
    titleAndMeta('yourTitle');
    

    这在你的页面中,这在你的 header.php 中

    function titleAndMeta($title)
     echo '<title>$title</title>';
    

    【讨论】:

    • 这将在函数调用时回显标题标签,即包含标题之后。这不会解决原始海报的问题。
    猜你喜欢
    • 2013-03-17
    • 1970-01-01
    • 1970-01-01
    • 2022-06-14
    • 2014-06-25
    • 1970-01-01
    • 2020-04-05
    • 2013-05-27
    • 1970-01-01
    相关资源
    最近更新 更多