Unable to remove canonical url

#204440
  • Resolved Rabin Biswas
    Rank Math free

    I trying this code to disable canonical url in my custom pages but it’s not working

    add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
    $canonical = false;
    return $canonical;
    }, 9999);

    These codes are working fine but the above code isn’t.
    add_filter( 'rank_math/opengraph/url', function( $url ) {
    $url = false;
    return $url;
    });

    add_filter( 'rank_math/frontend/remove_credit_notice', '__return_true' );

Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention. I’m sorry for any inconvenience this issue may have caused you.

    Could you please also share the URL where you are trying to remove the canonical to check further?

    However, here is another snippet that you can use to only remove the canonical and not the rest of the Rank Math meta:

    /**
     * Allow changing of the canonical URL.
     *
     * @param string $canonical The canonical URL.
     */
    add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
            //create conditional here to check for the custom page
            if(condition){
                return '';
            }
    	return $canonical;
    });

    I hope that helps.

    Thank you, and looking forward to your update.

    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 ‘Unable to remove canonical url’ is closed to new replies.