Canonical URL Default

#4025
  • Resolved Jax
    Rank Math free

    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.

    ​​​​​​

    Jax
    Rank Math free

    thanks

    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.

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

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