dongqiang8058 2016-05-15 04:42 采纳率: 100%
浏览 28

自动填充其他元标记的元标记

I'm creating a website with multiple pages.. I'm adding going to have to add META tags to every page however I would like to know if there we a way to extract stuff from existing tags and add them to other tags.

So, for example these tags already exist in the static HTML pages:

<meta name="description" content="Description 01"/>
<title>Title 01</title>

Now any way to extract these values from every page and insert them as other tags into other pages.

So Home page would already contain:

<meta name="description" content="Description Home"/>
<title>Title Home</title>

and these would automatically be added:

<meta itemprop="name" content="Title Home">
<meta itemprop="description" content="Description Home">
<meta name="twitter:title" content="Title Home">
<meta name="twitter:description" content="Description Home">
<meta property="og:title" content="Title Home" />
<meta property="og:description" content="Description Home" />

And the contact page would already contain:

<meta name="description" content="Description Contact"/>
<title>Title Contact</title>

and these would automatically be added:

<meta itemprop="name" content="Title Contact">
<meta itemprop="description" content="Description Contact">
<meta name="twitter:title" content="Title Contact">
<meta name="twitter:description" content="Description Contact">
<meta property="og:title" content="Title Contact" />
<meta property="og:description" content="Description Contact" />
  • 写回答

1条回答 默认 最新

  • douao1579 2016-05-15 05:16
    关注

    Make it dynamic instead

    Create header.php then insert the following code

    <!DOCTYPE html>
    <html>
        <head>
            <meta name="description" content="<?php echo $page_desc ?>"/>
            <title><?php echo $page_title ?></title>
            <meta itemprop="name" content="<?php echo $page_title ?>">
            <meta itemprop="description" content="<?php echo $page_desc ?>">
            <meta name="twitter:title" content="<?php echo $twt_title ?>">
            <meta name="twitter:description" content="<?php echo $twt_desc ?>">
            <meta property="og:title" content="<?php echo $og_title ?>" />
            <meta property="og:description" content="<?php echo $og_desc ?>" />
        </head>
        <body>
    

    Create footer.php then insert the following code

        </body></html>
    

    Create index.php as your first page

    <?php
        // the page title and description should be declared first before you include the header and footer
        $page_title = 'My Page Title';
        // same as the others
        $twt_title = $page_title;
        $og_title = $page_title;
    
        $page_desc = 'My Page Description';
        // same as the others
        $twt_desc = $page_desc;
        $og_desc = $page_desc;
    
        include 'header.php';
    ?>
    <!-- some page contents -->
    <?php include 'footer.php'; ?>
    

    Create about.php as another page

    <?php
        // the page title and description should be declared first before you include the header and footer
        $page_title = 'About us';
        // same as the others
        $twt_title = $page_title;
        $og_title = $page_title;
    
        $page_desc = 'My Page Description';
        // same as the others
        $twt_desc = $page_desc;
        $og_desc = $page_desc;
    
        include 'header.php';
    ?>
    <!-- some page contents -->
    <?php include 'footer.php'; ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)