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

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

Topic paginate-comments-links noindex robots.txt pagination comments Wordpress

Category Web


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

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.