Black Friday & Cyber Monday Offer | Flat 20% OFF on Lifetime & All Themes Package. Use coupon code BFCM24 | Offer valid till 5th Dec 2024 Buy Now

WordPress Website Templates

Find Professional WordPress themes Easy and Simple to Setup

inner banner

How To Remove Rel Canonical From Noindexed Pages In WordPress Using The All In One SEO Plugin

Noindexed Pages
The All In One SEO Plugin is a very popular plugin for bloggers that are using WordPress. Reports indicate that the active installs of this particular plugin has already reached more than three million.

But although it is very useful, there is one issue about this plugin that confronts its users. This plugin has the habit of adding rel canonical to every noindexed page.

If a user noindexed a particular page or post, the plugin in adds rel canonical as well. Every time this happens, it will really be a problem to the user, especially if he understands that it is not good to add rel canonical in a noindexed page.

The Fix From The Team Of AIOSEOP

Thankfully, the team of AIOSEOP has a general fix to this issue. Their advice is to use filter hooks that will refine the way this particular plugin will handle different situations. Basically, the user needs to add some code to the functions.php file to customize his setup.

Using Hooks To Do Away With Rel Canonical

The code that is responsible for this particular customization is simple and straight forward. You need to add a filter through one code line and also the function that takes away rel canonical based on the required conditions.

An example would be removing rel canonical from any archive page or category because these pages are being noindexed at present.

The Set Up Process

Here is the way the process could be set up:

  • The user must back up his WordPress blog. Backing up everything is important each time the user wants to work with his WP code. He has to ensure that he can go back to his latest version.

    In addition to backing up his own blogs, he should also ensure that his hosting provider is also backing up his entire site every day.

  • The next step is to open functions.php file for his theme. This should be located in the root directory of his theme. If the user has no clue about this, he should contact his hosting provider or developer how he could find the correct file.

    He should also learn more about how functions.php works by doing some research on the subject online before he could go on to step three.

  • Before adding the new code, the user must back up his current functions.php file. This is the ideal way he can make sure that he will have a stable version of this file that he can use to go back to if necessary. He can just download it, and then do a back-up save, and then go back to its original file in order to customize the code.
  • The user must then add the following code to his functions.php file. This will check if the present page is an archive page or a category page. But it will not indicate rel canonical in its html if the page is.


    add_filter('aioseop_canonical_url','remove_canonical_url', 10, 1);
    function remove_canonical_url( $url ){
    global $post;
    if( is_category() ){
    return false; // Remove the canonical URL for categories.
    } elseif (is_archive() ){
    return false; // Remove the canonical URL for archives.
    }
    return $url;
    }

  • The user must then upload the functions.php file to his site, in the root directory of his theme. If he is not sure where this is located, he must ask for help from his developer or hosting provider.

    If it is important that he should not start uploading this file in various sections of his WordPress install.

  • The code must be tested by the user by accessing his archive pages or category pages. He could see if the code works if rel canonical is not in the html. It will be just the meta robots tag that will be seen
  • The user must continue the testing of his file. He needs to double check his homepage, his blog posts and his web pages to be sure that rel canonical is being indicated correctly.

    He needs to be sure that there is no conflict with his theme and his other plugins. If there are conflicts here, he can expect some weird behavior.

  • If after all the testing and the user sees that there seems to be nothing wrong but everything seems to be working fine, then he is all set to go. He can be sure that he has correctly removed rel canonical from noindexed pages in WordPress using the All In One SEO Plugin.
  • The user can also give additional conditions by using the same functions if he wants to remove rel canonical from specific posts or pages based on the ID.

    For instance, the user could add the code below to the functions that he has created earlier if he wants to check a certain post or page. He just needs to add an else if that will check for a post or page ID:

    elseif ( $post->ID === 2){
    return false; // Remove the canonical URL for post #2.
    }

    The user can apply this strategy for archives or categories and also for specific posts and pages. There is a need to edit certain codes, but it provides an ideal solution which does not really require a long time to set up.

    James Gorski Author

    In addition to being the editor at designrfix and writing about tech, web and graphic design among other subjects, I love “unplug” and be outdoors hiking and enjoying nature. If you can’t reach me, it’s probably because where I am at doesn’t have cell phone reception.