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

时间:2020-02-04 06:20:22

标签: php wordpress woocommerce

我指的是特定产品,而不是所有产品。我已经用Google搜索,找不到任何答案。

2 个答案:

答案 0 :(得分:2)

有很多方法可以给猫皮。

您可以使用Robot.txt。

您可以禁止证书人网址:

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”),请在<head></head>之间粘贴此标签,(您有tons of plugins可帮助您自定义标题,无需编码):

<?php if ($post->ID == X) { echo '<meta name="robots" content="noindex,nofollow">'; } ?>

您甚至可以使用||运算符来阻止多个:

<?php if ($post->ID == X || $post->ID == Y) { echo '<meta name="robots" content="noindex,nofollow">'; } ?>

或者您可以阻止某个帖子标题:

<?php if(is_single('Hello World')): ?>

多个帖子标题,始终使用||运算符:

<?php if ( is_single('big-announcement') || is_single('new-update-coming-soon') ) ) : ?>

应用更改后:

应用更改后,请等待几天。然后转到Google Webmaster,检查哪些页面已建立索引,哪些页面未建立索引。

答案 1 :(得分:0)

有一些解决方案,也许您想使用元标记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');
相关问题