[英]Auto populate meta tags from other meta tags
我正在创建一个包含多个页面的网站。.我要添加必须在每个页面上添加META标签,但是我想知道是否有一种方法可以从现有标签中提取内容并将其添加到其他标签中。
因此,例如,这些标记已存在于静态HTML页面中:
<meta name="description" content="Description 01"/>
<title>Title 01</title>
现在,可以通过任何方法从每个页面提取这些值,并将它们作为其他标签插入到其他页面中。
因此主页将已经包含:
<meta name="description" content="Description Home"/>
<title>Title Home</title>
这些将自动添加:
<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" />
联系人页面将已经包含:
<meta name="description" content="Description Contact"/>
<title>Title Contact</title>
这些将自动添加:
<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" />
使其动态化
创建header.php,然后插入以下代码
<!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>
创建footer.php,然后插入以下代码
</body></html>
创建index.php作为您的第一页
<?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'; ?>
创建about.php作为另一个页面
<?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'; ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.