Problems with Canonical tags

#212121
  • Resolved Hristo Hristov
    Rank Math free

    Hello dear RankMath,
    We were using RankMath for a while and we are very satisficed with your plugin.
    However, we have a small problem with canonical tags(on some places, RankMath put duplicate canonical tags or in the wrong place).
    So, what code to use to disable RankMath only on the page, if we have a multiple canonical tags.
    Kind Regards,

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    Thanks for contacting us.

    You can modify and use this filter to remove the canonical tag from the pages you want: https://rankmath.com/kb/filters-hooks-api-developer/#change-canonical-url

    Hope this helps. Let us know if you need any further assistance.

    Thank you for your reply.
    “I forgot to mention, we have a blog. We have two different files. One is the header.php and the other is the header-posts.php. The first one renders in the homepage of the blog and the other in the single page posts. I need a way to deactivate the canonical only in the header.php (index.php page). I did what the documentation suggests, created a new file “rank-math.php”, added the code and I saw no change.

    <?php

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

    ?>

    Am I doing something wrong? Do I need to include this file on my index.php page or it is happening automatically?

    Thanks for your prompt response.

    Ankit
    Rank Math business

    Hello,

    Thank you for your reply

    Suppose you want to hide the canonical URL from your front page, for that you can use the following filter. You can modify it according to your needs.

    Place the filter code inside the rank-math.php or 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()){ // you can add your condition here 
                return '';
            }
    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 3 replies - 1 through 3 (of 3 total)

The ticket ‘Problems with Canonical tags’ is closed to new replies.