How to set up self-referencing canonicals for paginated blog pages with RankMath

#514951
  • Resolved Sonja
    Rank Math free

    Hello, I have a client with an extensive blog post section with 15 paginated pages, but all of them are canonicalised to the domain.com/blog (the main blog page) which is not ideal from the SEO perspective.

    Can I change this and make sure that all paginated blog pages such as domain.com/blog/page/2 are self-referencing instead canonicalised to the main blog page?

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    Thank you for contacting us and sorry for any inconvenience that might have been caused due to that.

    Rank Math adds a self-referencing canonical URL by default for your paginated pages. But if it is not working then you can try the following filter to force the self-referencing canonical URL of your blog pagination:

    add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
    	global $wp;
    	$current_slug = home_url( $wp->request );
    
    	if ( is_paged()) {
    		$canonical = $current_slug . '/';
    	}
    	return $canonical;
    });
    

    Here’s how you can add filter/hook to your WordPress site:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Let us know how it goes.

    Thank you.

    ​​​​​​​

    Sonja
    Rank Math free

    Yes, it worked. Thanks a lot.

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)

The ticket ‘How to set up self-referencing canonicals for paginated blog pages with RankMath’ is closed to new replies.