Discover in this tutorial how to add the noindex meta tag in WordPress pages of your choice using code.
If you prefer not to use an SEO plugin and control the basics with a little bit of code, this tutorial will be interesting to you.
On a website there are usually several pages that you don’t want to be indexed by search engines. For example:
- Privacy policy
- Cookies policy
- Legal notice
- Pages intended for administrators or users (web documentation, my account…)
In this tutorial we are going to see how you can add the noindex meta tag to achieve this.
Snippet to prevent specific WordPress pages from being indexed by search engines
Add the following code snippet to your functionality plugin:
To see this and another 919 code snippets of this website, login or subscribe here.
With this snippet you use the following the conditional tag is_page
to add the noindex meta tag in the page header.
In this case, you would be indicating not to index the pages with identifier 7, 40 and 66.
You can get the page ID by checking the URL when you edit the page or, if you want to make it easier for yourself, get it displayed directly in the WordPress admin with this tutorial.
If you prefer, you can also use the mode in which you indicate the title, for example, is_page( 'Privacy policy' )
.
Conclusions
Do you want some WordPress pages not to be indexed and thus prevent them from appearing in search engine results? Now you know how to do it with a little bit of code.
Any questions? Let me know in the comments.
And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉