Hello,
Thank you for contacting Rank Math today.
You can add the following custom filter to your theme’s functions.php file to modify the canonical URL:
/**
* Allow changing of the canonical URL.
*
* @param string $canonical The canonical URL.
*/
add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
$custom_url = RankMath\Post::get_meta( 'canonical_url', get_the_ID() );
if ( $custom_url ) {
$canonical = rtrim($custom_url,"/");
}
return $canonical;
});
I hope this info helps. Thank you.
​​​​​​
Hello,
We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.
If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/?filter=5#new-post about your overall experience with Rank Math? We appreciate your time and patience.
If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.
Thank you.