【问题标题】:How to prevent a product on WooCommerce from being indexed by Google? [closed]如何防止 WooCommerce 上的产品被 Google 索引? [关闭]
【发布时间】:2020-02-04 06:20:22
【问题描述】:

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

【问题讨论】:

  • 我投票决定将此问题作为题外话结束,因为关于 SEO 的问题在这里是题外话。相反,您应该在webmasters.stackexchange.com 上问这个问题

标签: php wordpress woocommerce


【解决方案1】:

给猫剥皮的方法有很多种。

您可以使用 Robot.txt。

您可以禁止 certians 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),请将其粘贴在 <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查看哪些页面被索引,哪些页面没有被索引。

【讨论】:

  • 我喜欢 PHP 的方式。但是我们必须将元标记放在 下还是可以放在 HTML/PHP 页面上的任何位置?否则我需要在 WordPress 主题中编辑 header.php 文件。
  • @hivolih247,我添加了一个插件链接,可以帮助你做到这一点
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-23
    • 1970-01-01
    相关资源
    最近更新 更多