How to hide specific tags from webshop filter function?

Hi everyone,

I use tags in my webshop for customers so they can filter on certain products that they’re searching. But I would like to use tags for me as well in de the backend without customers seeing them.

I know there are several ways to import this. I found this that I would like to use:


  

Browse by tag:

  

So if I start a tag with _ it doesn’t how up in the frontend of the webshop.

But I can’t seem to find the exact spot where I should add this code. I took over this webshop from a colleague that isn’t working with us anymore, and I don’t always understand his coding.

If you would like to check on a page I want to implement this: https://bickerykerst.nl/collections/happy-jul

Somewhere here?

{% if is_filter_by_available or section.settings.sort_enable %}
      
        

          

            

              {% if section.settings.tags_enable %}
                {% unless collection.all_tags.size == 0 %}
                  

                    
                    

                      
                      {% include 'icon-chevron-down' %}
                    

                  

                {% endunless %}
              {% endif %}

Sorry and thanks in advance, I don’t have a lot of knowledge of coding/liquid.

Hey @Anne-Marieke ,

Replace this:

{% for tag in collection.all_tags %}
    {%- assign new_url = tag | link_to_tag: tag | split: 'href="' | last | split: '"' | first -%}
    
{% endfor %}

With this:

{% for tag in collection.all_tags %}
  {% if tag contains '_' %}
  {%- assign new_url = tag | link_to_tag: tag | split: 'href="' | last | split: '"' | first -%}
  
  {% endif %}
{% endfor %}

And let me know if it works for you or not.

Thank you!!

@Amarjyoti thank you for your response

I changed the code, but now only the tags with ‘_’ in front will show up in the frontend of the store, whereas I don’t want the _tags to show up, only the tags without a _ prefix.

Hey @Anne-Marieke ,

Got it. Can you please replace that code with the below one?

{% for tag in collection.all_tags %}
  {% unless tag contains '_' %}
  {%- assign new_url = tag | link_to_tag: tag | split: 'href="' | last | split: '"' | first -%}
  
  {% endunless %}
{% endfor %}

Let me know if this works.

Thank you!!

2 Likes

@Amarjyoti Yess, thank yóu! That did the trick :slight_smile:

1 Like

Can you please provide what .liquid to enter this code and were in the code to place it. I want to be able to filter out tags from the “Filter and Sort” option on my website (see link to screenshot below) NOTE: My Theme is Sunrise and is Shopify Online 2.0 (latest update).

Link to image screenshot of filter and sort to have tags excluded: https://cdn.shopify.com/s/files/1/0051/1102/1640/files/filterandSort-001.jpg?v=1671554446

Where exactly do I place this code? Do I create a snippet for it?

I am using Publisher 2.0 theme.

Thank you,

DeAnne

Can you please let us know where did you place the code? Please and thanks!