Set Canonical To First Page on WordPress Categories Pages and WordPress SEO

To set the rel=canonical pointing to the first page of a paged list in WordPress (for categories or tags) and using WordPress seo you can easily add a filter with a small piece of code.

How it works

WordPress SEO, once generated the canonical for a page, trigger the filter¬†wpseo_canonical. We attach our code to that filter and check if we are in a “paged” condition and if we are in an archive or home context. When those conditions are true we recompute the canonical to the one of the main page for the archive (or the home) and replace the original canonical.

You can easily add this code on your functions.php (child) theme file or inside a custom plugin.

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