Paginated pages canonical

#219904
  • Resolved Vladimir Lalovic
    Rank Math free

    Hi,

    I need help in setting up a canonical on paginated pages in categories. I have for example /category/p/2 and I want it to point to the main page /category/ I know and read about that it is not a very good practice but I want to try anyway. I already set up paginated pages to noindex, follow but I wanted to set up a canonical on them also as there is currently none. I saw that you have a custom php snippet for canonical but I’m not very good with programming so I would appreciate some kind of directive in that sense.. Thanks in advance.

Viewing 1 replies (of 1 total)
  • Hello,

    Thanks for contacting us. Sorry for the delay and any inconvenience that might have been caused due to that.

    As I can check, you have set your paginated pages to noindex. We only add the canonical to pages that are set to index, if you have enabled the option to noindex the paginated pages the canonical won’t show up on those pages.

    And the canonical is used to inform the search engine crawlers about the original content and stop them from indexing the duplicate content. Since you have already stopped paginated pages from getting indexed, you don’t need a canonical tag.

    If you still want to add the canonical URL to those pages then you will have to set them as index first, from WP Dashboard > Rank Math > Titles & Meta > Misc Pages, and disable the Noindex Paginated Pages option. Then add the code given below in your theme’s functions.php file to set the canonical URL as the URL of the main page:

    add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
    	if ( is_paged() ) {
    			$link = $_SERVER['REQUEST_URI'];
    			$arr = explode('/p/', $link,);
    			$canonical = home_url($arr[0]. '/');
    		}
    		return $canonical;
    });

    Hope this helps. Let us know if you need any further assistance.

    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 1 replies (of 1 total)

The ticket ‘Paginated pages canonical’ is closed to new replies.