I’m working on customizing my Shopify store and need help with Liquid templating. I want to display products only when they don’t have a particular tag.
Currently I know how to check if a product has a specific tag like this:
{% if item.tags contains 'exclude' %}
<!-- product has the tag -->
{% endif %}
But I need the reverse logic. I want to show products that do NOT have the ‘exclude’ tag on my collection page. How can I write a condition that checks when a product doesn’t contain a certain tag? What’s the proper syntax for this in Shopify Liquid?
You can also use the unless tag with cleaner syntax. Just write {% unless item.tags contains 'exclude' %} then your product display code, and close with {% endunless %}. This reads way more naturally than negating booleans and keeps your template cleaner. I’ve found it super useful for multiple tag exclusions since you can chain conditions without making things messy. The unless tag just inverts the condition - it only runs the code when the condition’s false. Works reliably across different Shopify themes in my experience.
flip the logic with unless instead of if - {% unless item.tags contains 'exclude' %} then your product code {% endunless %}. perfect for hiding tagged products on collection pages. i’ve used this method forever.
You can also use the unless tag or negate with == false. Just write {% if item.tags contains 'exclude' == false %} to explicitly check that it’s false. This works great for complex conditions and makes debugging way easier since the intent is super clear when you’re reading the code. Both methods do the same thing, but some devs prefer the explicit boolean check over unless because it’s more readable.