Canonical URL Setting for Paginated Blog Pages

#729040
  • Resolved Mehmet Tahca
    Rank Math free

    I’ve created a page for blog posts with Elementor and it has a pagination.
    This is a page not an archive template.
    Here is the example of URL’s.
    https://domain.com/blog/
    https://domain.com/blog/2/
    https://domain.com/blog/3/

    The problem is all pages set to canonical to /blog/
    But i want to set up 2nd pages canonical to 2nd, 3rd to 3rd etc.

    I’ve tried to add code below to functions.php but canonical url didn’t changed.
    add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
    $current_url = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

    // Check if the URL contains '/page/' and is not the first page
    if ( false !== strpos( $current_url, '/page/' ) && ! is_paged() ) {
    $canonical = strtok( $current_url, '?' ); // Set canonical to the first page
    }

    return $canonical;
    });

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hello, I’m sorry to hear about the issue you’re facing with setting up the canonical URLs for your paginated blog pages.

    To set up the canonical URLs for paginated blog pages in Rank Math, you can use the Advanced tab in the Rank Math meta box. You can change the Canonical URL field to point to the main source of your content. This will inform search crawlers of the main page if you have pages or posts with similar content.

    Here’s a step-by-step guide on how to do this:

    1. Edit the post/page that contains the paginated content.
    2. Navigate to the Advanced tab of the Rank Math in your editor. If you’re unable to find the Advanced tab, please enable the advanced mode from WordPress Dashboard → Rank Math SEO → Dashboard.
      Navigate to the Advanced tab
    3. In the Canonical URL field, add the URL you want to be the canonical URL for that specific post or page.
      Enter the canonical URL
    4. Once you’ve added a canonical URL, save or update your post or page.

    If you’ve already tried this method and it didn’t work, please ensure that you’ve correctly added the code snippet to your functions.php file. If you’re still facing issues, please reply to this ticket, and a human agent from the Rank Math Support team will assist you further.

    I hope this helps! Let me know if you have any other questions or need further assistance.

    Sources:
    How to Fix ‘Duplicate, Submitted URL Not Selected as Canonical’ Issue in Google Search Console » Rank Math
    Bulk Editing Options in the Rank Math SEO Plugin
    Alternate Page with Proper Canonical Tag Status in Google Search Console » Rank Math
    How to Customize Breadcrumbs in Rank Math » Rank Math
    Setting Canonical URLs in Rank Math » Rank Math

    Hello,

    Thank you for your patience.

    Please update the filter to this instead to set a self-referencing canonical on your paginated URLs:

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

    And here’s a guide to adding the filter to your website:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Let us know how this goes.

    Thanks for reply @Reinelle
    I’ve added code above to functions.php but canonicals still same.

    Hello,

    The paginated pages are being generated dynamically on your site, and you can notice that Rank Math is not generating the rel=next and rel=prev tags due to that.

    The paginated pages should also return true for the is_paged() function of WordPress, but it seems they don’t on your site, and that’s why there is no adjacent links even on the main page.

    In this case, you may try this filter instead to apply the self-referencing canonical:

    add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
    	$url = 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    	if(strpos($url,'blog') !== false){
    		return $url;
    	}
    	
    	return $canonical;
    });

    Let us know how this goes.

    Yes latest code block works perfect.
    Thank you so much.

    Hello,
    
    You’re welcome.

    We are super happy that this issue is already resolved. 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 6 replies - 1 through 6 (of 6 total)

The ticket ‘Canonical URL Setting for Paginated Blog Pages’ is closed to new replies.