Noindex collection page but not tagged pages

I am looking for the right code snippet for setting a collection page to noindex, but its tagged pages must remain indexable.

So for example:

…/collections/widget is the collection to be set to noindex

but

…/collections/widget/blue and …/collections/widget/green etc are to remain indexable

Something like the following sets every page to noindex, I have tried different variations as well.

{% if template contains ‘collection’ and canonical_url contains ‘/collections/widget’ %}

{% endif %}

but the inclusion of something like and current_tags == false breaks and nothing is set to noindex

What is the correct code to exclude the tagged pages from being set to noindex?

Hi @Garner , glad to help you with your question. I’m sure, my given answer will help to solve your problem as adding the given code below in the section

1: Go to Online Store > Actions > Edit Code > theme.liquid

And paste code between head tag like this

{% if collection.handle == “widget” %}

{% endif %}

Hopefully, that solves your problem. If not, please let me know if you’re seeing any other issues.