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.

add_filter('wpseo_canonical', 'my_wpseo_canonical');

function my_wpseo_canonical($canonical) {
    if (is_paged()) {
        if (is_home()) {
            return home_url();
        }

        if (is_archive()) {
            $url = get_category_link(get_queried_object_id());
            return $url;
        }
    }

    return $canonical;
}

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.

Similar Posts

Leave a Reply