Set NoIndex on WordPress Categories Pages with WordPress SEO

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.

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.

My excuses for my bad english but it's the only way I have to communicate with you. Would you suggest a correction? Leave a comment, thank you!

Leave a Reply