Set canonical URL’s for category page/2 page/3

#407181
  • Resolved Fred
    Rank Math free

    Hi i want set canonical URL for all categories.

    For example:

    sitename.com/cars/page/2
    sitename.com/cars/page/3
    sitename.com/cars/page/3

    like this. for this pages i want set canonical url: sitename.com/cars/
    and i have many categories i cant do it manuel.

    how i can do it?

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Fred
    Rank Math free

    Hi, i found this help from you. is it right?

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

    Hello,

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

    Yes, that filter should help you set the canonical URL of your paginated categories.

    The filter should be added to your active theme’s functions.php file. Here’s another way to apply the filter using the rankmath.php file:
    https://rankmath.com/kb/filters-hooks-api-developer/#adding-filters-and-hooks-in-rank-math-php

    Let us know how this goes.

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

The ticket ‘Set canonical URL’s for category page/2 page/3’ is closed to new replies.