【发布时间】:2020-02-04 06:20:22
【问题描述】:
我指的是特定产品,而不是所有产品。我用谷歌搜索,找不到任何答案。
【问题讨论】:
-
我投票决定将此问题作为题外话结束,因为关于 SEO 的问题在这里是题外话。相反,您应该在webmasters.stackexchange.com 上问这个问题
标签: php wordpress woocommerce
我指的是特定产品,而不是所有产品。我用谷歌搜索,找不到任何答案。
【问题讨论】:
标签: php wordpress woocommerce
给猫剥皮的方法有很多种。
您可以禁止 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$
如果您想禁止某个帖子(将“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查看哪些页面被索引,哪些页面没有被索引。
【讨论】:
有一些解决方案,也许您想使用元标记 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');
【讨论】: