Canonical Issue In Pagination

#375556
  • Resolved Parin Doshi
    Rank Math free

    Hi Suppoet,

    We are facing issue in set canonical links for pagination.

    Like we have this main url Domain/resources/ and it’s pagination url is like Domain/resources/page/5.

    So we want to set canonical for the pagination url like Domain/resources/page/5.

    Please let us know how can we set it?

    Thanks!

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

    Thank you for contacting Rank Math support and bringing your concern to our attention.

    With Rank Math the implementation of canonical on the paginated pages sets the canonical of the main index page on all paginated pages.

    For example, the page https://yourdomain.com/resources/page/2 would and should have a canonical of https://yourdomain.com/resources/. This is the recommended way of canonical implementation in paginated pages as Google sees them as the same page as the main page.

    However, if you wish to change this, you can customize the following filter to use the current URL as the canonical:

    /**
     * Allow changing of the canonical URL.
     *
     * @param string $canonical The canonical URL.
     */
    add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
    	return $canonical;
    });

    Hope that helps you. Thank you.

    Parin Doshi
    Rank Math free

    Hi Jeremy,

    Thanks for the reply.

    I’m not sure about what is the code for customize that filter for the shared requirement and where i need to place it.

    Can you please guide on this.

    Thanks!

    Prabhat
    Rank Math agency

    Hello,

    Please try adding the below filter to the website:

    add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
    	$uri = 'https://your-domain.com/'.$_SERVER['REQUEST_URI'];
    	if(false !== strpos($uri, '/page/')){
    		$canonical = $uri = strtok($uri, '?');
    	}
    	return $canonical;
    });

    In the above code, please replace “your-domain.com” with your actual domain.

    You can follow this guide to add the code to the website:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    After adding the code, clear your website’s cache and see if you get the desired canonical URLs.

    Let us know how that goes.

    Thank you.

    Parin Doshi
    Rank Math free

    Hello Prabhat,

    Thanks for your help.

    I have tried this filter with our domain name first in function.php file but not worked there so tried in rank-math.php file as suggested in this.
    Screenshot : https://prnt.sc/pIYUqRhj8xQ7

    function.php : https://prnt.sc/gvLdTv99t30B
    rank-math.php : https://prnt.sc/Vj8cWv5TYk5O

    After placed code we have review by clear cache also but not able to get expected result.

    Please giude more on this.

    Thanks!

    Prabhat
    Rank Math agency

    Hello,

    We might need to take a closer look at the settings. Please edit the first post on this ticket and include your WordPress & FTP logins in the designated Sensitive Data section.

    Please do take a complete backup of your website before sharing the information with us.
    Sensitive Data Section

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    https://wordpress.org/plugins/temporary-login-without-password/

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    https://wordpress.org/plugins/wp-security-audit-log/

    We really look forward to helping you.

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Hello Team,

    I have shared required details.

    It will not show canonical until uncheck this option (https://prnt.sc/1t2eXkdLaKbF) from admin->settings-> reading menu.

    Please help to solve our shared issue.

    Thanks!

    Hello,

    That is perfectly normal that with that option enabled the canonical is missing from your pages.

    The option you mentioned sets your entire website to noindex and when that happens our plugin won’t add the canonical as the pages will not be indexed and as such don’t need a canonical tag.

    When the page is set to index our plugin will add the self-referencing canonical.

    Hope this helps clarify your doubts.

    Don’t hesitate to get in touch if you have any other questions.

    Hello Miguel,

    Thanks for the reply.

    Our isssue is not like cannonical is not showing.

    Cannonical is showing but we have some different requirement that all the things we have mentioned in this thread.

    Please review it and help to fullfill our requirement.

    Thanks!

    Prabhat
    Rank Math agency

    Hello,

    I logged into your staging site and tried to access the paginated resources page but it is returning a 404 error. The page is loading on the live website but not on the staging one.

    Please have a look at this and let us know when the page is accessible on the staging site so that we can investigate further.

    Looking forward to helping you.

    Thank you.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

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

The ticket ‘Canonical Issue In Pagination’ is closed to new replies.