How to Remove Canonical Tagging System Applied by Yoast’s WordPress SEO plugin

Today I am going to write on a little different topic that is not directly related to Technology. When I changed the theme of this site few months ago, I also applied some inner changes at HTML and coding level of the theme. At that time I faced a problem related to Canonical Tagging system. In fact I want to disable canonical tags on certain posts while using the WordPress SEO plugin. In this post you will learn how we can remove this tag.

So when I changed the theme, I also replaced All in One SEO plugin with the most popular WordPress SEO plugin. Like the former, the latter plugin also uses its own canonical tags. But AIOS plugin gives you one check option from where you can disable the function at any time and the whole control is shifted back to worcpress’s own system. Unfortunately WordPress SEO doesn’t offer such once-click option at the admin end. However, it gives you some filters which you can insert in the functions.php file and control some parts of the plugin according to your need.

NB: I am again using All in One SEO plugin on this site due to some reasons I will discuss later in another post.

If you are still using  AIOS plugin, you can go to the General Settings page and uncheck “Canonical URLs” option as shown in this screenshot.

AIOS

In case your are using WordPress SEO plugin, you’ll have to add a filter in the functions.php file just before the closing of PHP as shown in the screenshot below.

functions.php-1

Here is the exact code:
add_filter( 'wpseo_canonical', '__return_false' );
It will disable canonical tags across the site and no page, no post and no archive will show this tag. But if you want to disable tagging function on certain posts, pages or category archives, you’ll have to use this code instead of the code mentioned above.
function wpseo_canonical_exclude( $canonical ) {
global $post;
if (is_single( '348' )) {
$canonical = false;
}
return $canonical;
}

As you know every post, page, category or any another archive has its own unique ID in the wordpress. So in the above example we used 348 which is the post ID for a specific post where the canonical tag will not show. If you don’t know how to find the ID, here is a good article for you. To hide this tag from multiple posts, use this code.
function wpseo_canonical_exclude( $canonical ) {
global $post;
is_single( array( 17, 19, 1, 11 ) ) {
$canonical = false;
}
return $canonical;
}

There are a lot of conditional tags available on WordPress Codex page which you can use to disable Yoast’s wordpress SEO plugin’s canonical tags on any category, archive, post or page. The above mentioned are only few examples. I hope you understand now how to achieve the goal. If you are still facing any problem regarding this topic, you can leave a comment below and I’ll try to help you.

Enter email to get Updates in your inbox:

Updated 10 years agoCategorized as Web

By A. Usman

Loves new tech, especially from Apple and Google.

View all of A. Usman's posts.

9 Replies

  1. Hi,
    I hope you could help me.
    I need to change the canonical URL from http to https… I just only need to add the S on every canonical.
    Do you know if we can use some filter to achieve this?

    1. A. Usmansays:

      Hi Lucky, isn’t it a better way to redirect all http requests to https rather than keeping the both versions??

      1. That’s for sure and I already did it. Unlucky me I set the canonical URL inside every products, using the canonical setting of yoast.
        So now… my redirects are pointing to the https but hey in the meanwhile I’m telling at google that the canonical is http…
        That’s not good at all I guess…

        1. A. Usmansays:

          Yoast pulls th url on the basis of Blog URL set in the settings. Go to WordPress Settings and replace http://www. mysite.com to https://www. mysite.com.

          I hope it will fix the problem.

    1. You don’t know how much time I spent to get it done. It’s great to know that there are many others who are looking for such type of information.

  2. Tabbysays:

    Removing canonical tagging system applied by WordPress SEO plugin by Yoast can be somewhat complicated but with the knowledge, and tips from experts like you, can certainly help a lot of people who are struggling on what to do and how to do it.

  3. KTsays:

    I’m trying to disable the Yoast canonical tag on my home page (static front page) only. I added this to functions.php but no luck. Any suggestions?

    function wpseo_canonical_exclude( $canonical ) {
    global $post;
    if (is_front_page()) {
    $canonical = false;
    }
    return $canonical;
    }

    1. ECsays:

      KT, looks like you were just missing the filter call after your code:
      add_filter( ‘wpseo_canonical’, ‘wpseo_canonical_exclude’ );

      function wpseo_canonical_exclude( $canonical ) {
      global $post;
      if (is_home()) {
      $canonical = false;
      }
      return $canonical;
      }
      add_filter( ‘wpseo_canonical’, ‘wpseo_canonical_exclude’ );

Leave a reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.