WordPress SEO Plugin Removes Rel Canonical from Non-Indexed Pages

The All in One SEO plugin is widely used among bloggers and WordPress site owners, with over 3 million installations. Despite its power and usefulness, there is an issue that bothers users: the plugin automatically adds a rel canonical tag to pages that are marked as unindexed. This can create undesirable consequences for SEO.

When a page or post is marked as non-indexable, the plugin adds rel canonical to it. This is undesirable, since using rel canonical on non-indexed pages can lead to incorrect indexing or lower rankings in search results.

Contents of the article:

  • How to solve the problem
  • How to get rid of Rel Canonical using hooks
  • How to set up a process

The plugin development team has proposed a solution to the problem, recommending the use of filters to change the behavior of the plugin. In this case, the user needs to make changes to the functions.php file to configure the plugin to work correctly with canonical links.

How to get rid of Rel Canonical using hooks

The code required to configure the plugin and remove rel canonical is simple. It allows you to disable the addition of the rel tag to pages that should not be indexed.

To do this, you need to use filters in your code to control whether canonical URLs are added or removed based on page conditions.

How to set up a process

To make the changes you want, follow these steps:

  1. Create a backup copy of the site: It is always recommended to create a full backup of your site before making changes. This is necessary so that in case of an error you can restore the working version.
  2. Open the functions.php file: Locate the functions.php file of your current WordPress theme. It should be located in the theme's root directory. If you cannot find this file, contact your hosting provider or developer.
  3. Make a backup copy of the file: Before editing the functions.php file, make a backup copy of it. This will give you the opportunity to revert to the original version of the file if something goes wrong.
  4. Add code: Add the following code to your functions.php file to remove the canonical URL for archive and category pages:
 add_filter(aioseop_canonical_url, eRemove_canonical_url, 10, 1); function remove_canonical_url($url) { global $post; if (is_category()) { return false; // Убираем канонический URL для категорий. } Elsafe(is_archive()) { return false; // Убираем канонический URL для архивов. } return $url; } 

The added code checks whether the page is a category or an archive, and if so, removes the rel canonical tag.

  1. Download the modified file: Once the code is added, upload the modified functions.php file back to your theme root folder. This is an important step because placing files incorrectly can lead to errors.
  2. Test the changes: Go to the category or archive pages to check if the rel canonical tag has been removed. It should disappear, but the robots meta tag should remain.
  3. Check out other pages: Once you have verified that the changes have been successfully applied to the archive and category pages, double-check other pages such as the home page or posts to ensure that rel canonical is working correctly.
  4. Removal on specific pages: If you need to remove rel canonical from individual pages or posts, you can add a check by page ID:
 Elsafe ($post->ID === 2) { return false; // Убираем канонический URL для поста с ID 2. } 

In conclusion

Using these steps, you can easily remove the rel canonical tag from non-indexable pages or individual posts on WordPress. Although some additional code editing will be required for some users, the proposed solution is quite simple and effective for most sites.

If you have any questions or need additional clarification, write to the SEO studio "SEO COMPUTER" with any questions at email info@seo.computer.

ID 7564

Send a request and we will provide a consultation on SEO promotion of your website