Find out in this tutorial how to add the noindex meta tag in dynamic WordPress pages, such as archive or search, using code.
If you are one of those who prefer not to use a SEO plugin and control the basics with a little code, this tutorial will be interesting for you.
Adding the noindex meta tag to a dynamic page can be tricky since you don’t have access to it from the WordPress administration. But you can solve this problem by using WordPress conditional tags.
Let’s see how to do it:
Snippet to prevent WordPress dynamic pages from being indexed by search engines
Add the following code snippet to your functionality plugin:
With this snippet you use the following conditionals to add the noindex meta tag in the page header:
You can modify the conditionals to suit your needs. For example, if you want to avoid indexing tags and categories you should use this snippet:
In this case you use conditionals:
Even if you wanted to avoid indexing a particular category you could do it by adding its ID or slug. For the category with ID=11 it would be:
You can see that by modifying WordPress conditional tags you can control which dynamic WordPress pages will be indexed in search engines or not.
Do you want to prevent some dynamic WordPress pages from being indexed and appearing in search engine results? Now you know how to do it with a little bit of code.
If you have any question, please leave it in the comments. And if you want to give me a suggestion for future snippets, please send it through the contact form.
Benefits of being a subscriber. 🙂