Noindex特定类别分页页面

时间:2019-05-20 09:53:23

标签: woocommerce pagination noindex

WooCommerce正在为父类别创建类别分页页面。我们不希望将这些索引编入索引,但我无法确定如何最好地做到这一点。

例如我有 https://www.i-hled.co.uk/product-category/light-engines/led-count-one/page/2/

该页面升至第31页,但我只希望索引主类别的页面而不是这些分页的页面。这不是站点范围的要求,我仍然希望其他页面分页能够建立索引,因此我无法进行全局更改。

我看了以下

<meta name="robots" content="follow, <?php echo 
(get_query_var('paged')==1)?'index':'noindex'?>" /><meta name="robots" 
content="follow, <?php echo (get_query_var('paged')==1)?'index':'noindex'? 
>" />

但这会删除所有分页索引

我也想到了标题中的这些内容,但是我无法弄清楚分页如何工作。

if ( is_product_category(led-count-one){
echo "<meta name=\"robots\" content=\"noindex\" />";
}

是否可以在htaccess文件中执行此操作?还是header.php文件中的代码是最佳选择?

https://www.i-hled.co.uk/product-category/light-engines/led-count-one/page/2/ https://www.i-hled.co.uk/product-category/light-engines/led-count-one/page/3/

不会被索引,但是 https://www.i-hled.co.uk/product-category/light-engines/led-count-one/one-led/page/2/ https://www.i-hled.co.uk/product-category/light-engines/led-count-one/one-led/page/3/

将被索引

1 个答案:

答案 0 :(得分:1)

我使用All in One SEO API对其进行了如下修复

 add_filter( 'aioseop_robots_meta', 'change_robots_meta_value' );

 function change_robots_meta_value( $robots_meta_value ) {
 if( is_product_category( 'PYO' ) && is_paged() ) {
      $robots_meta_value = 'noindex,nofollow';
 }
if( is_product_category( 'Light Engines' ) && is_paged() ) {
      $robots_meta_value = 'noindex,nofollow';
 }
    if( is_product_category( 'LED Count' ) && is_paged() ) {
      $robots_meta_value = 'noindex,nofollow';
 }
        if( is_product_category( 'Micromoles' ) && is_paged() ) {
      $robots_meta_value = 'noindex,nofollow';
 }
            if( is_product_category( 'Size' ) && is_paged() ) {
      $robots_meta_value = 'noindex,nofollow';
 }
                if( is_product_category( 'Wavelength' ) && is_paged() ) {
      $robots_meta_value = 'noindex,nofollow';
 }
                    if( is_product_category( 'Thermal' ) && is_paged() ) {
      $robots_meta_value = 'noindex,nofollow';
 }
 return $robots_meta_value;
}
相关问题