How To Remove Rel Canonical From Noindexed Pages In WordPress Using The All In One SEO Plugin
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:
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.
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.
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;
}
If it is important that he should not start uploading this file in various sections of his WordPress install.
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.
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.