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?
User | RANK |
---|---|
42 | |
42 | |
32 | |
24 | |
21 |
Make the shift from discounts to donations, and witness your business not only thrive fina...
By Holly Dec 4, 2023On our Shopify Expert Marketplace, you can find many trusted third party developers and fr...
By Arno Nov 27, 2023You've downloaded the Search & Discovery app from the Shopify App store, and as you're ...
By Skye Nov 8, 2023