WordPress SEO plugin removes Rel Canonical from non-indexed pages

print · Время на чтение: 4мин · - · Опубликовано · Обновлено

playListen to this article

All in One SEO removes Rel Canonical.WordPress SEO plugin removes Rel Canonical – You may have heard of the powerful All in One SEO plugin that many WordPress bloggers use. The plugin has reportedly received over 3 million installs. plugin All in One SEO looks very powerful, and although it is very useful, this plugin has a particular problem that bothers its users. The plugin automatically adds rel canonical to every non-indexed page.

Whenever a user does not index a particular page or post, the plugin will add a rel canonical to that page or post. This is a real problem for users as they are discouraged from using rel canonical on non-indexed pages.

The content of the article:

How to solve a problem

The plugin development team came up with a generic solution to this problem. They encourage users to use filter hooks to change how this plugin handles different situations.

In other words, the user needs to apply some code in the functions.php file to configure the plugin settings.

How to get rid of Rel Canonical with hooks

The code responsible for setting the options for this particular fix is quite simple.

You just need to add code line filters and functions to remove rel specs based on the conditions you want.

How to set up a process

To set up the process, follow these steps:

1. The first thing to do is back up your WordPress blog. Whenever a user decides to use WordPress code, it is always a good idea to back up everything. This is to ensure that changes do not break existing blogs and that you can revert to the latest version after making changes. In addition to backing up their own blog, users should also ensure that the hosting provider backs up the entire website on a daily basis.

2. The second step is to open the functions.php file for your WordPress theme. Ideally, this file should be located in the root directory of a specific theme. If you can't find the file or are having trouble finding it, it's recommended that you contact your hosting provider or developer to help you find the file you need.

3. After that, it is important to backup the current functions.php file before adding new code. This is so that you can use the unmodified version of the file if something goes wrong or doesn't work properly. You can simply download the file, save it as a backup, and go back to the original to make changes to the code.

4. It's time to add the code to the critical step of the functions.php file. The code below checks if the current page is an archive page or a category page. If the page is already canonical, this code will specify rel canonical in the HTML.

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 perfect place to download files. If you don't know where the root directory is, ask your developer or hosting provider for help and avoid uploading files to any or every part of your WordPress installation.

6. Once the file is uploaded to the correct location, it's time to test the code by visiting the archive or category page. The code succeeds if the canonical attribute does not exist in the HTML and only sees the robots meta tag.

7. The user must not stop the test file. You should double-check your home page, blog posts, and web pages to make sure the rel canonical is correct. You need to make sure that themes and other plugins stay in sync with the changes in the functions.php file and don't behave unexpectedly.

8. If after extensive testing you see no problems and everything works as expected, congratulations, you have successfully removed rel canonical from non-indexed pages using the All in One SEO plugin in WordPress.

10. Alternatively, you can use the same process to remove rel canonical from any specific page or post based on ID. To do this, you can add the following code to a function created to check for a specific page or post. You just need to add an elseif which specifies the id of the page or post.

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

Finally

Thus, users can remove rel canonical from all non-indexed archives or categories, as well as from any specific page or post.

Some more code editing may be required, but the method described above turns out to be the ideal solution, which does not require much time to set up.

Reading this article:

Thanks for reading: SEO HELPER | NICOLA.TOP

How useful was this post?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 315

No votes so far! Be the first to rate this post.

Читайте также:

Добавить комментарий

Your email address will not be published. Обязательные поля помечены *

eleven − 4 =