get_canonical_url filter not working

#223748
  • Resolved Kevin Webb
    Rank Math free

    Hello,

    I am the developer of a wordpress plugin that allows a site to republish articles (with permission from the original content owner) from another site. When an article is republished, I set some meta data in the post that allows me to identify the URL of the original content. When the post is displayed, I use the get_canonical_url() filter provided by wordpress, and I edit the canonical to be the url of the original content if it is a republished article. I’ve had a few users complain to me that the canonical is not correct for a republished article, and I realized it was because they were using RankMath SEO plugin. It seems like you guys are removing the hook that applies the get_canonical_url() filter. I feel like in your own custom hook, your plugin should be applying the get_canonical_url() filter to keep within the spirit of wordpress. Could you advise me on the best approach to solving my issue?

Viewing 1 replies (of 1 total)
  • Ankit
    Rank Math business

    Hello,

    Thank you for contacting the support and sorry for any inconvenience that might have been caused due to that.

    In order to modify the canonical URL you can use the below filter and modify it according to your needs:

    /**
     * Allow changing of the canonical URL.
     *
     * @param string $canonical The canonical URL.
     */
    add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
    	return $canonical;
    });

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    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 ‘get_canonical_url filter not working’ is closed to new replies.