Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何防止WooCommerce上的产品被Google索引?_Php_Wordpress_Woocommerce - Fatal编程技术网

Php 如何防止WooCommerce上的产品被Google索引?

Php 如何防止WooCommerce上的产品被Google索引?,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我指的是特定的产品,不是所有的产品。我在谷歌上搜索过,找不到任何答案。有一些解决方案,也许你想使用meta标签noindex。应该是这样的: function product_robots_noindex_meta_tags() { global $product; $no_robots_products = array(12,13,14); // list of product ids if ( $product && in_array($product

我指的是特定的产品,不是所有的产品。我在谷歌上搜索过,找不到任何答案。

有一些解决方案,也许你想使用meta标签noindex。应该是这样的:

function product_robots_noindex_meta_tags() {
    global $product;
    $no_robots_products = array(12,13,14); // list of product ids
    if ( $product && in_array($product->get_id(), $no_robots_products) ) {
        echo '<meta name="robots" content="noindex" />';
    }
}
add_action('wp_head', 'product_robots_noindex_meta_tags');

给猫剥皮有很多种方法

您可以使用Robot.txt。 您可以禁止认证URL:

User-agent: *
Disallow: /wp-admin/
Disallow: /wp-includes/
或某些文件类型:

User-agent: *
Disallow: /pdfs/ # Block the /pdfs/directory.
Disallow: *.pdf$  # Block pdf files from all bots. Albeit non-standard, it works for major search engines.
或图像:

User-agent: Googlebot-Image
Disallow: /images/cats.jpg #Block cats.jpg image for Googlebot specifically.
或GIF:

User-agent: Googlebot-Image
Disallow: /*.gif$
您可以使用PHP: 如果您不想使用您的帖子ID来禁止某个帖子更改ID,您可以将其粘贴在两者之间,这样可以帮助您自定义标题,而无需编码:

<?php if ($post->ID == X) { echo '<meta name="robots" content="noindex,nofollow">'; } ?>
或者您可以阻止某个帖子标题:

<?php if(is_single('Hello World')): ?>
应用更改后:
应用更改后,请等待几天。然后转到并检查哪些页面被索引,哪些页面未被索引。

我喜欢PHP的方式。但是我们必须把meta标记放在HTML/PHP页面的下面,或者它可以放在HTML/PHP页面的任何地方吗?否则,我需要在WordPress主题中编辑header.php文件。@hivolih247,我添加了一个带有插件的链接,可以帮助您做到这一点。我投票以主题外的形式结束这个问题,因为关于SEO的问题在这里是主题外的。相反,你应该问这个问题
<?php if(is_single('Hello World')): ?>
<?php if ( is_single('big-announcement') || is_single('new-update-coming-soon') ) ) : ?>