The Internet Marketing Driver

  • GSQi Home
  • About Glenn Gabe
  • SEO Services
    • Algorithm Update Recovery
    • Technical SEO Audits
    • Website Redesigns and Site Migrations
    • SEO Training
  • Blog
  • Contact GSQi

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

July 12, 2017 By Glenn Gabe 7 Comments

Share
Tweet
Share
Email
716 Shares

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:
https://www.seroundtable.com/noindex-canonical-google-18274.html
https://www.seroundtable.com/archives/020151.html

John Mueller explains that it’s best to not mix rel canonical and noindex (at 56:59 in the 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 wpbeginner.com.
  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.

GG

 

Share
Tweet
Share
Email
716 Shares

Filed Under: google, seo, tools

Connect with Glenn Gabe today!

Latest Blog Posts

  • Smart Delta Reports – How To Automate Exporting, Filtering, and Comparing Google Search Data Across Timeframes Via The Search Console API and Analytics Edge
  • Filters and Pills in the Google SERPs – How the addition of filters, tabs, and dynamic organization in the search results can impact visibility and clicks
  • How To Use GSC’s Crawl Stats Reporting To Analyze and Troubleshoot Site Moves (Domain Name Changes and URL Migrations)
  • Google Search Console (GSC) reporting for Soft 404s is now more accurate. But where did those Soft 404s go?
  • Google’s December 2020 Broad Core Algorithm Update Part 2: Three Case Studies That Underscore The Complexity and Nuance of Broad Core Updates
  • Google’s December 2020 Broad Core Algorithm Update: Analysis, Observations, Tremors and Reversals, and More Key Points for Site Owners [Part 1 of 2]
  • Exit The Black Hole Of Web Story Tracking – How To Track User Progress In Web Stories Via Event Tracking In Google Analytics
  • Image Packs in Google Web Search – A reason you might be seeing high impressions and rankings in GSC but insanely low click-through rate (CTR)
  • Google’s “Found on the Web” Mobile SERP Feature – A Knowledge Graph and Carousel Frankenstein That’s Hard To Ignore
  • Image Migrations and Lost Signals – How long before images lose signals after a flawed url migration?

Web Stories

  • Google’s Disqus Indexing Bug
  • Google’s New Page Experience Signal

Archives

  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • July 2019
  • June 2019
  • May 2019
  • April 2019
  • March 2019
  • February 2019
  • January 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • June 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • January 2018
  • December 2017
  • November 2017
  • October 2017
  • September 2017
  • August 2017
  • July 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
  • October 2016
  • August 2016
  • July 2016
  • June 2016
  • May 2016
  • April 2016
  • March 2016
  • February 2016
  • January 2016
  • December 2015
  • November 2015
  • October 2015
  • September 2015
  • August 2015
  • July 2015
  • June 2015
  • May 2015
  • April 2015
  • March 2015
  • February 2015
  • January 2015
  • December 2014
  • November 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • May 2014
  • April 2014
  • March 2014
  • February 2014
  • January 2014
  • December 2013
  • November 2013
  • October 2013
  • September 2013
  • August 2013
  • July 2013
  • June 2013
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • January 2013
  • December 2012
  • November 2012
  • October 2012
  • September 2012
  • August 2012
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • GSQi Home
  • About Glenn Gabe
  • SEO Services
  • Blog
  • Contact GSQi
Copyright © 2021 G-Squared Interactive LLC. All Rights Reserved. | Privacy Policy

We are using cookies to give you the best experience on our website.

You can find out more about which cookies we are using or switch them off in settings.

The Internet Marketing Driver
Powered by  GDPR Cookie Compliance
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

Strictly Necessary Cookies

Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.

If you disable this cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.

3rd Party Cookies

This website uses Google Analytics to collect anonymous information such as the number of visitors to the site, and the most popular pages.

Keeping this cookie enabled helps us to improve our website.

This site also uses pixels from Facebook, Twitter, and LinkedIn so we publish content that reaches you on those social networks.

Please enable Strictly Necessary Cookies first so that we can save your preferences!