Code to remove canonical url

#33999
  • Resolved Chris
    Rank Math free

    Is there a code to remove canonical URLs in rank math?

    I’m not sure it’s from a plugin or rankMath.

    I’ve tried various wordpress hooks but none have worked.

    • This topic was modified 4 years, 1 month ago by Chris.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Chris
    Rank Math free

    Hello,

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

    Thank you.

    Hello,

    Thank you for contacting Rank Math today.

    You can use the following filter to remove canonicals on certain pages:

    /**
     * Allow changing of the canonical URL.
     *
     * @param string $canonical The canonical URL.
     */
    add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
            //target a page using its page id
            if(is_page('page_id')){
                return false;
            }
    	return $canonical;
    });
    

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

The ticket ‘Code to remove canonical url’ is closed to new replies.