0

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/光引擎/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/

将被索引

4

1 回答 1

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;
}
于 2019-08-15T09:41:17.997 回答