【问题标题】:Set page title after <head> tags在 <head> 标签之后设置页面标题
【发布时间】:2017-09-18 23:07:59
【问题描述】:

我有没有页眉/页脚的单页。他们只是有每个页面的内容。

我的 index.php 页面有包含页面标题的模板,但我想在每个页面中设置每个页面标题。

在 index.php 页面中,我将页面文件包含在 &lt;body&gt; 标记中

【问题讨论】:

    标签: php html


    【解决方案1】:

    另一种解决方案

    你可以这样做

    index.php

    <html>
    <head>
    <title><?php title_func(); ?></title>
    </head>
    
    <body>
     require "content.php";
    </body>
    </html>
    

    内容.php 只需在任何地方制作此功能

     <?php 
        function title_func(){
            echo "title here";
        } 
    ?>
    

    【讨论】:

      【解决方案2】:

      我有一个替代方法可能有用。

      不要关闭索引文件中的 head 标签,然后在内容文件中使用标签设置标题并关闭 head 标签。

      类似

      index.php

      <html>
      <head>
      <!--links--->
      <?php require "content.php";?>
      </html>
      

      content.php 文件:

      <title>YOUR TITLE</title>
      </head>
      <body>
      <!--your data-->
      </body>
      

      【讨论】:

        【解决方案3】:

        您可以使用 javascript 或 jquery 来执行此操作。 首先,给标题标签一个id

        <title id='page_title'>My Page</title>
        

        然后在每一页上,就像这样:

        <script>
            var new_page_title= 'My New Title'
        </script>
        

        最后在模板的页脚部分,只需使用 javascript 或 jquery 更改名称:

        // javascript
        document.getElementById ('page_title').innerHTML = new_page_title;
        
        // jquery
        $ ('#page_title').html (new_page_title);
        

        编辑

        @Purushotam 说的也可以

        【讨论】:

        • 如果 SEO 对你很重要,那么我认为你会想要远离这一点
        • 这是真的
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-02-19
        相关资源
        最近更新 更多