最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

pagination - Set noindex page-comment from Pages 2, 3 and More?

programmeradmin0浏览0评论

I use All in one seo pack plugin.

I see that Google indexed page comments (that are a pages generated from paginated comments).

The example url are the followings:

  1. URL canonical - mydomain/url-canonical
  2. URL comment page - mydomain/url-canonical/comment-page-3

The problem is that 'URL comment page' has itself as canonical, and not the main page.

I'd like to set as noindex all comment-page for all postes. Is it possible?

I see that AIO SEO has aioseo_filter_robots_meta, but I do not understand how to filter it for comment-page.

I have the following code, but it is only for singular:

add_filter( 'aioseo_robots_meta', 'aioseo_filter_robots_meta' );

function aioseo_filter_robots_meta( $attributes ) {
    if ( is_singular() ) {
       $attributes['noindex']  = 'noindex';
       $attributes['nofollow'] = 'nofollow';
    }
    return $attributes;
 }

There is a way to add meta tag robots noindex only for all comment-page?

Solved by following code:

 add_filter( 'aioseo_robots_meta', 'aioseo_filter_robots_meta' );

function aioseo_filter_robots_meta( $attributes ) {
global $cpage;   
    if (!empty($cpage) && $cpage > 0) {
       $attributes['noindex']  = 'noindex';
    }
    return $attributes;
 }

I use All in one seo pack plugin.

I see that Google indexed page comments (that are a pages generated from paginated comments).

The example url are the followings:

  1. URL canonical - mydomain/url-canonical
  2. URL comment page - mydomain/url-canonical/comment-page-3

The problem is that 'URL comment page' has itself as canonical, and not the main page.

I'd like to set as noindex all comment-page for all postes. Is it possible?

I see that AIO SEO has aioseo_filter_robots_meta, but I do not understand how to filter it for comment-page.

I have the following code, but it is only for singular:

add_filter( 'aioseo_robots_meta', 'aioseo_filter_robots_meta' );

function aioseo_filter_robots_meta( $attributes ) {
    if ( is_singular() ) {
       $attributes['noindex']  = 'noindex';
       $attributes['nofollow'] = 'nofollow';
    }
    return $attributes;
 }

There is a way to add meta tag robots noindex only for all comment-page?

Solved by following code:

 add_filter( 'aioseo_robots_meta', 'aioseo_filter_robots_meta' );

function aioseo_filter_robots_meta( $attributes ) {
global $cpage;   
    if (!empty($cpage) && $cpage > 0) {
       $attributes['noindex']  = 'noindex';
    }
    return $attributes;
 }
Share Improve this question edited Jan 16, 2021 at 10:40 Giulio asked Jan 16, 2021 at 10:06 GiulioGiulio 511 silver badge8 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1
function noindex_comments_pages()
{
    global $cpage;
    if (!empty($cpage) && $cpage > 1) {
    echo '<meta name="robots" content="noindex">';
    echo "\n";
    }
}
add_action( 'wp_head', 'noindex_comments_pages', 9 );
发布评论

评论列表(0)

  1. 暂无评论