All things Shopify and commerce
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?
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.
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
Where do you paste the code you suggested?
By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024