Get all our 20+ Elementor themes worth $609 at just $59! Limited time offer. Get It Now

WordPress Website Templates

Find Professional WordPress themes Easy and Simple to Setup

inner banner

The All in One SEO Plugin in WordPress to Remove Rel Canonical From Noindexed Pages

All in One SEO Plugin
You may have heard about the mighty All in One SEO Plugin that many WordPress Bloggers are using. As per the reports, this plugin has already received more than three million installs.

The All in One SEO plugin seems all mighty and powerful and although it is very useful, there is one particular issue with this plugin that is troubling its users.

The plugin automatically adds rel canonical to every noindexed page.

Whenever a user noindexed a particular page or post, the plugin adds rel canonical to that page or post. This is a real problem to the user as it is not advisable to user rel canonical on a noindexed page.

How to fix the issue

The developing team of the plugin has come up with a general fix to this issue. They recommend users to use filter hooks that change the way this plugin handles different situations.

In other words, the users need to apply some code to the functions.php file to customize the plugin setup.

How to use Hooks to get rid of Rel Canonical

The code responsible for customizing the setup for this particular fix is pretty simple and straightforward.

All you need is adding a filter through a code line and in the function, in order to take away rel canonical based on the required conditions.

How to set up the process

You need to go through the following steps so that the process could be set up:

  1. The first thing to do is to back up the WordPress blog. It is always recommended to back up everything whenever the user decides to work with the WordPress code. This is to ensure that the changes will do no harm to the existing blogs and you can move back to the latest version once the changes are made. Apart from taking a back up of your own blogs, the users must ensure that the hosting provider keeps backing up the whole website on a daily basis.
  2. The second step is to open the functions.php file for your WordPress theme. Ideally, the file must be located in the root directory of the particular theme. If you are unable to find the file or face any difficulty in finding it, it is advised to contact the hosting provider or developer to help you find the correct file.
  3. After that, it is important to take back up of the current functions.php file before adding the new code. This is to make sure that you have an untouched version of the file to use if something goes wrong or doesn’t work out as expected. You can just download the file, save it as a back-up, and then go back to the original file to make changes to the code.
  4. Now it’s time for the crucial step of adding the code to the functions.php file. The following code is to check whether the present page is an archived page or a category page. This code will indicate rel canonical in HTML if the page is already canonical.


    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;
    }

  5. The next step is to upload the modified functions.php file to the site, in the root directory of the theme. This is the ideal location to upload the file. If you are unaware where the root directory is located, take help of the developer or the hosting provider and avoid uploading the file in any or every section of the WordPress install.
  6. Once the file is uploaded in the right location, it is time to test the code by accessing the archived or category pages. The success of the code lies in the fact if rel canonical is not present in the HTML, and only meta robots tag is seen.
  7. The user must not stop testing the file. You must recheck your homepage, blog posts, and web pages to ensure that rel canonical is being indicated correctly. You need to confirm that the theme and other plugins are in sync with the changes in the functions.php file and are not misbehaving.
  8. If after the thorough testing you find that there is nothing wrong and everything seems to work as they are supposed to, then congratulations, you have successfully removed rel canonical from noindexed pages using the All in One SEO Plugin in WordPress.
  9. Additionally, you can use the same process to remove rel canonical from any specific page or post based on the ID. For that, the following code can be added to the already created functions to check a certain page or post. All you need is to add an elseif that will indicate a page or post ID.


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

Conclusion

This way user can remove rel canonical from all the noindexed archives or categories and also from any particular page or post.

There may still a need to edit certain other codes, but the above way proves to be an ideal solution which doesn’t take much time to set up.

Ashish Sharma Author

Ashish Sharma is the Chief Marketing Officer at WeDigTech, a Mobile App Development Company in India. He is responsible for marketing activities that have to do with creating, communicating and delivering offerings that have value for clients or business partners.