Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @agumba,

    Thank you for contacting Rank Math support.

    To force the self-referencing canonical on your paginated pages, you may need to use this filter on your site:

    add_filter( ‘rank_math/frontend/canonical’, function( $canonical ) {
    $canonical = ‘https://’.$_SERVER[‘HTTP_HOST’].$_SERVER[‘REQUEST_URI’];
    return $canonical;
    });

    Here is how to add a filter to your site: https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Hope that helps.

    Thread Starter agumba

    (@agumba)

    Hello,

    Thank you for your response.

    I added the following code:

    add_filter('rank_math/frontend/canonical', function($canonical) {
        $uri = $_SERVER['REQUEST_URI'];
        // Remove page number
        $uri = preg_replace('/\/page\/\d+\//', '/', $uri);
        
        // Create the full URL
        $canonical = 'https://' . $_SERVER['HTTP_HOST'] . $uri;
        return $canonical;
    });

    This modification achieved the desired result. Thank you for your attention and support. I wish you healthy days.

    Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @agumba,

    We are glad that everything has been sorted out.

    Please feel free to reach out to us again in case you need any other assistance.

    We are here to help.

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Removing Page Numbers from Canonical URLs in a Multilingual Setup with Translate’ is closed to new replies.