1

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.com/url-canonical
  2. URL comment page - mydomain.com/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; } 

1 Answer 1

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 ); 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.