Canonical tag issue

#203575
Viewing 5 replies - 1 through 5 (of 5 total)
  • Ankit
    Rank Math business

    Hello,

    Thank you for contacting Rank Math, and sorry for any inconvenience caused.

    If you are using a custom page to show the blog posts, then you can easily add the trailing slash by editing that page.

    Please see the screenshot below:
    https://ibb.co/gT75V62

    If that is not the case, Do let us know so we can troubleshoot further.

    We are not using custom page to show blog homepage.

    It’s a subfolder url – https://www.truppglobal.com/blog/

    We are using wordpress in subfolder.

    What changes need to be done in functions.php file?

    Ankit
    Rank Math business

    Hello,

    Thank you for your reply.

    Please add below filter code in your theme’s functions.php file:

    add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
    	if ( is_home() ) {
    		return user_trailingslashit( $canonical );
    	}
    	return $canonical;
    });

    Looking forward to helping you.

    Hello Ankit,

    Above code is not working.

    Is there any way to change canonical for blog homepage https://www.truppglobal.com/blog/ ?

    Or disable it for blog homepage?

    Ankit
    Rank Math business

    Hello,

    Thank you for your reply.

    Try the below code for trailing slash:

    add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
    	if ( is_front_page() ) {
    		return user_trailingslashit( $canonical );
    	}
    	return $canonical;
    });

    To remove the canonical tag from the home page, you need to put the below code inside your themes function.php file.

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

    I hope that helps. Thank you, and please don’t hesitate to contact us anytime if you need further assistance.

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

The ticket ‘Canonical tag issue’ is closed to new replies.