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

Glenn Gabe

google, seo, tools

How to remove rel canonical from noindexed pages.

When performing SEO audits, it’s not unusual to surface pages being noindexed that also contain rel canonical. And that setup does’t make sense. Using the meta robots tag or x-robots-tag with noindex tells the engines to not index the page, while rel canonical tells the engines which is the preferred url for indexing. You can end up sending Google very confusing signals. Google’s John Mueller has explained this many times in the past and it could lead to some strange results.

Here are some links where John has mentioned this before:

John Mueller explains that it’s best to not mix rel canonical and noindex (at 56:59 in the video):

YouTube video

And in an SEO world where certain things are out of your control, I’m a firm believer in taking control where you can. This is one of those situations. I always recommend that clients send the strongest signals possible about which pages should be indexed, and which ones shouldn’t be indexed. And providing both rel canonical and noindex definitely sends mixed signals.

SEO WordPress Plugins and Relinquishing Control
Many site owners using WordPress utilize SEO plugins to handle various tasks. For example, optimizing titles and metadata, managing indexation of different page categories, and more. But since the plugins are created by third parties, there are times it’s hard to customize your setup. And that can leave you with holes in your SEO armor.

One extremely popular SEO plugin, which I’ve used for a long time, is the All In One SEO Plugin, or AIOSEOP for short. It’s a plugin that has over three million active installs. There is also a pro version with additional functionality (and that’s what I’m running now). I’ve found the plugin to be extremely helpful for managing SEO tasks on WordPress sites.

All In One SEO Plugin

I love the plugin, but for whatever reason, it always added rel canonical to noindexed pages. For example, if you noindex your categories or archive pages, rel canonical was still added. If you noindexed a certain post or page, rel canonical was added there too. This was definitely a thorn in my side, especially knowing that it’s best to not include rel canonical on noindexed pages.

It bugged me enough that I decided to find a solution.

Reaching Out To The AIOSEOP Team
I reached out to the All In One SEO Plugin team to see if there was a solution for handling this. I received an email back quickly with a nifty solution. It ends up you can use filter hooks to refine how the All In One SEO Plugin handles various situations. In a nutshell, by adding some code to your functions.php file, you can customize your setup. This is exactly the type of customization I was looking for.

So I fired up a text editor, opened my functions.php file and started testing some functions for handling rel canonical and noindex on certain page types. Below, I’ll cover how you can implement the same thing on your WordPress site.

How To Use Hooks To Remove Rel Canonical From Noindexed Pages
The code that handles this customization is pretty straight forward. You’ll add a filter via one line of code and then the function that removes rel canonical based on the condition that’s met. For my example, I wanted to remove rel canonical from any category or archive page, since those pages are currently being noindexed.

Here’s how to set this up:

  1. Back up your WordPress blog. Any time you are going to mess with your WP code, you should absolutely back up everything. Make sure you can easily revert to the latest version. I automatically back up my blog daily and I also have my hosting provider backing up my entire site daily.
  2. Open the functions.php file for your theme. It should be located in your theme’s root directory. If you have no idea what I’m referring to, then speak with your developer or hosting provider about finding the right file. If you want to learn more about functions.php, you can check out this article on
  3. Back up your current functions.php file before adding the new code. This is a great way to ensure you have a stable version of the file that you can revert back to, if needed. Simply download the file, save a backup, and then come back to the original file to customize the code.
  4. Add the following code to your functions.php file. It checks if the current page is a category page or archive page and doesn’t write out rel canonical in the html if it 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;

  1. Upload the functions.php file to your site (again, in your theme’s root directory). If you aren’t sure where this file should go, seek help first. Don’t just start uploading the file to different areas of your WordPress install.
  2. Test the code by visiting your category pages or archive pages. If the code works, you should NOT see rel canonical being written out in the html. You should just see the meta robots tag using noindex.
    Only publishing noindex without rel canonical.
  3. You’re not done testing yet. Double check your homepage, your blog posts, and your pages to ensure rel canonical IS being written out properly. You want to make sure there’s not a conflict with other plugins or with your theme, which could result in some funky behavior.
  4. If all looks good, then you’re all set! You can rest assured that your category and archive pages are not providing both rel canonical and the meta robots tag using noindex.

You Can Handle Noindexed Pages and Posts Too
Even though the code I provided above handles categories and archived pages, you can absolutely tailor the code to handle any page or post. You could provide additional conditions via the same function to remove rel canonical from specific pages or posts based on their ID.

For example, you could add the following code to the function we created earlier to check for a specific post. Just add another elseif that checks for a post ID:

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

Summary – Rel canonical and noindex don’t mix.
If you’re using the All In One SEO Plugin, then this is a great solution for making sure rel canonical and noindex aren’t mixed together on the same page. Again, that can send mixed signals to Google. This technique can be used for major page types like categories or archives, as well as for specific pages or posts. Sure, you’ll need to edit some code, but it’s a flexible solution that shouldn’t take very long to set up.

Like I said earlier, don’t send mixed signals to Google. Take control and send clear signals instead.



7 thoughts on “How To Remove Rel Canonical From Noindexed Pages In WordPress Using The All In One SEO Plugin [Tutorial]”

    • No problem Boni! I think you’ll find it to be a flexible solution. You can handle a number of scenarios easily via filter hooks. And the folks at AIOSEOP were great when I reached out about finding a way to remove rel canonical from noindexed pages. If you’re not afraid of code, then this can be a great way to go. :)

    • Great question, and one I’ve received a lot since writing this post. One of my clients actually custom developed a solution for Yoast and it’s working for them now. It’s very similar to the method covered in my post. But I need to check it out further and test it myself before recommending that approach.

      Also, Yoast mentioned on Twitter that he might be adding that functionality to the plugin itself. You might want to reach out to him about that to check the ETA. I hope that helps.

  1. And what if there is a canonical to the noindex page itself? I understand you’re sending mixed signals when you point to a index page within the canonical and the robots says noindex.

    • Yes, that would be problematic for sure. You are telling Google not to index the current page, but index some other page instead (but that page has a directive telling Google to not index it). Sounds confusing, right? :)

      You should only provide urls you want indexed via the canonical url tag. Those urls should be indexable, return a 200 code, etc. I hope that helps.

Comments are closed.