Canonical URL Default

  • Resolved Jax

    Is there a place to change the default canonical URL style? I’d rather not go into each page and change the canonical from including the “/” to a URL w/o the slash

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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.




    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 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.

Viewing 3 replies - 1 through 3 (of 3 total)

The ticket ‘Canonical URL Default’ is closed to new replies.