Discover in this tutorial how to add the noindex meta tag in WooCommerce product or category pages, using code.
If you prefer not to use a SEO plugin and control the basics with a little code, this tutorial will be of interest to you.
If you have (or manage) a store in WooCommerce and you have a landing page dedicated to the product, you may not be interested in indexing the product page. And the same can happen with the product categories (or some of them).
But adding the noindex meta tag to a dynamic page can be more complicated since you don’t have access to it from the WordPress administration. However, you can solve this problem by using WooCommerce conditional tags.
Let’s see how to do it:
Snippet to prevent WooCommerce product pages and categories from being indexed in search engines
Add the following code snippet to your functionality plugin:
To see this and another 997 code snippets of this website, login or subscribe here.
With this snippet you use the following conditionals to add the noindex tag in the page header:
is_product()
is_product_category
( )
You can modify the conditionals to suit your needs. For example, if you only want to avoid indexing product categories, you would use this snippet:
To see this and another 997 code snippets of this website, login or subscribe here.
In this case you only use the conditional is_product_category
( ).
Even if you wanted to avoid indexing a specific product category you could do it by adding its ID or slug. For the category with ID=7 it would be: is_product_category(7)
or is_product_category('t-shirts')
.
You can see that by modifying WooCommerce conditional tags you can control which WooCommerce pages will be indexed in search engines or not.
Conclusions
Do you want to prevent WooCommerce product pages and/or categories 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. 🙂