I need to use <meta name="robots" content="noindex">
in my "thank you page".
Google instructions says that I need to put it between <head>
tags but my head tags are shared (php included) from same file for all pages, even for those pages which I want to be indexed.
What is the right practice for this?
This is how I am including it on all pages (basic method), <head>
tags are inside head.php file:
<?php include 'head.php';?>
答案 0 :(得分:0)
我通常用通用头做的事情是在包含头文件之前先声明一些PHP变量。这些对于每个页面而言都是唯一的,因此可以根据页面更改元名称等。
示例:
<?php
$metaName='robots';
$metaContent='noindex';
include_once('head.php');
?>
然后在您的头文件中:
<head>
<meta name="<?php echo $metaName; ?>" content="<?php echo $metaContent; ?>">
//What else you may have
</head>
然后,根据您的需要,您始终可以重组逻辑,添加并使用更多的变量等,但这足以给您大致的认识。
如果不想在每个页面上都设置$metaName
和$metaContent
变量,则可以选择在 head 文件中为它们提供一些默认值。
示例:
<?php
if(!$metaName) {
$metaName='default value';
}
if(!$metaContent) {
$metaContent='default value';
}
?>