Debut: Hiding Shopify All Product Tags in Filter But Show Specific Ones Using A Custom Prefix

Hi experts and Gurus. I am trying to do the opposite of this

https://burstcommerce.com/how-to-hide-shopify-product-tags-from-collection-filters/

I have hundreds of tags already on each product and collections and I don’t want to have to go in and add a prefix to each one so I figure maybe do the opposite of this article I found. I would like customers to be able to filter by product type, so hide all current tags but show any new ones with a prefix. For example, I can add new tags like _Men’s Watches etc. and that would be the only tags that show in the filter by on collection pages. I would

Can anyone please help to re-write the code to use for this? Very much appreciated. My store is https://kate-mcenroe-nyc.myshopify.com/admin/menus

Hi @KatKat1 for solving coding|technical issues like this to drastically increase your chances of solutions in the future, it helps to show at least some legwork and reduce the problem and provide minimal code in the post itself to be considerate of other peoples time. Most of the time you’ll just become another ignored post because who wants to read a 1,000+ word tutorial to figure out which parts your referring too and THEN “rewrite” the whole thing, or the answers will be flawed.

Otherwise your gambling on the luck of random timing luck of who sees your post and happens to understand the issue and are interested in it ;). Those are some bad odds not a good longterm approach.

trying to do the opposite of this

Since there’s no NOT-contains when your not able to use boolean comparison because “contains” is being used then roughly you need to invert any inclusion/exclusion logic; swapping ifs for unless’s and vice versa.

psuedo logic: if true skip this item in loop => unless true dont skip item ==> if not true continue( skip item )

{% assign tag_prefix = 'special_prefix' %}
{% for tag in tags %}
    {% unless tag contains tag_prefix  %} {% continue %} {% endunless %}
    ...
{% endif %}

Or set an intermediary variable to a boolean true|false, which you can then use standard boolean logic on it in an if tag, (!= aka not equals).

{% assign tag_prefix = 'special_prefix' %}
{% for tag in tags %}
    {% if tag contains tag_prefix %} {% assign show_tag == true %} {% endif %}
    {% if show_tag != true %} {% continue %} {% endunless %}
    ...
{% endif %}

or a known string value, or object, that can also be compared with boolean conditions

{% assign tag_prefix = 'special_prefix' %}
{% for tag in tags %}
    {% if tag contains tag_prefix %} {% assign show_tag == "show" %} {% endif %}
    {% if show_tag != "show" %} {% continue %} {% endunless %}
    ...
{% endif %}

That should get you started without seeing any of your existing code.

Also search forum posts for hiding tags using the underscore prefix convention for many similar discussions on tag exclusion techniques.

It’s easy to handle filter with tag prefix if you use this app https://apps.shopify.com/ultimate-search-and-filter-1. You can create a filter and in the Create filter form, you can specify your prefix for tags. i.e, you have tags like color:Red, color:Blue, color:Green. You can specify color: as the prefix for Tags type. Then the app automatically populars just the matched tags for that filter.