If you need to set to noindex the categories (or generally archives) pages (except the first one), you can add this little snippet of code changing the behavior of WordPress SEO.
WordPress SEO has a filter triggered just after the meta robots value has been computed. Intercepting this filter and checking the context, we can force the noindex
(or other robots directives) on specific pages.
add_filter('wpseo_robots', 'my_wpseo_robots'); function my_wpseo_robots($robots) { if (is_paged()) { if (is_home()) { return 'noindex'; } if (is_archive()) { return 'noindex'; } } return $robots; }
How it works
The wpseo_robots
filter is invoked with the current meta robots directive. If the paged condition is verified and we are in the home context or in the archives contexts, we force it to be change to noindex
.
Note that WordPress SEO, when the robots directive is set to noindex
removes the canonical.
Environment
This code has been tested in a clean WP installation with WordPress 4.9.8 and WordPress SEO 8.2 and Twenty Seventeen theme.