我在我的WordPress站点上使用Woocomerce。对于某些站点的打印版本,我使用类似以下http://www.mywebsite.de/kategorie/?wpp_export=print的参数
如何将这些urls设置为noindex。我在header.php中尝试了如下代码:
<?php
$url = $_SERVER['REQUEST_URI'];
if (strpos($url,'?') !== false) {
echo '<meta name="robots" content="noindex, follow" />' . "\n";
}
?> 但是代码不起作用。这些站点…的标题中没有noindex
你能帮我弄一下这个吗?
诚挚的问候
汤姆
发布于 2016-04-26 00:34:34
您应该做的第一件事是在functions.php文件中注册GET变量wpp_export:
add_action('init','add_get_val');
function add_get_val() {
global $wp;
$wp->add_query_var('wpp_export');
}然后我会尝试在你的header.php中使用类似这样的东西
<?php
if ( get_query_var('wpp_export') ) {
echo '<meta name="robots" content="noindex, follow" />';
}
?>您可以像这样测试GET变量的值:
<?php
if ( get_query_var('wpp_export') == 'print' ) {
echo '<meta name="robots" content="noindex, follow" />';
}
?>https://stackoverflow.com/questions/36841726
复制相似问题