How to hide some specific products from google search engine

Shopify Partner
4 0 1

Hello there, I have some products in my store. I want to hide all products instead of some.
I am using this code ==

{% if template contains 'product' %}
{% if product.handle == 'brown-shirt'
or product.handle == 'black-shirt' or product.handle == 'blue-shirt'
or product.handle == 'red-shirt' %}
<meta name="robots" content="allow">
{% else %}
<meta name="robots" content="noindex">
{% endif %}
{% endif %}

is this code is perfect or not?
anyone code expert please help me?

Replies 3 (3)
Shopify Partner
38 3 11

The code that you have provided is a conditional statement that checks the handle of the product being viewed on the product template and determines whether to allow or disallow search engines to index it. This code is correct in terms of its syntax and logic, but it may not be the best approach for hiding products in your store.


One potential issue with this approach is that it uses the noindex meta tag to prevent search engines from indexing the products. This may not be the most effective method for hiding products, as search engines may still be able to discover and crawl the pages for these products.


A better approach for hiding products in your store would be to use the product visibility settings in the Shopify admin. This allows you to set the visibility of individual products to "Hidden" so that they are not shown on your storefront or search results. This will prevent customers from accessing the pages for these products and will prevent search engines from indexing them.

Greetings Niclas
Senior Front-End Developer
Founder of Niccos Media
Based in Germany
Shopify Partner
5587 1260 1163

Hello @Muhammad-Jawad 


You can add tags to products like  this 


And using this code 

{% if template contains 'product' %}
{% assign no_index = false %}
{% for tag in product.tags %}
{% if tag contains 'noindex' %}
{% assign no_index = true %}
{% endif %}
{% endfor %}
{% if no_index %}

    <meta name="robots" content="noindex">
{% else %}
<meta name="robots" content="allow">
{% endif %}
{% endif %}

I hope the above is useful to you.

Kind & Best regards, 
GemPages Support Team

GemPages - Build any high-converting store pages for any business

- If you find my reply helpful, please hit Like and Mark as Solution
- Get connected: App Store | Blog | Community | Help Center
Not applicable

Where do you paste the code you suggested?