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:
- URL canonical - mydomain/url-canonical
- 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:
- URL canonical - mydomain/url-canonical
- 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
1 Answer
Reset to default 1function 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 );