Re: Hide certain tags from filter function

Solved

How to hide specific tags from webshop filter function?

Anne-Marieke
Excursionist
42 1 4

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: 

<div class="clearfix filter">
  <p>Browse by tag:</p>
  <select class="coll-filter">
    <option value="">All</option>
    {% for tag in collection.all_tags %}
      {% assign prefix = tag | slice: 0 %}
      {% if prefix == '_' %}
        {% continue %}
      {% endif %}
      {% if current_tags contains tag %}
        <option value="{{ tag | handle }}" selected>{{ tag }}</option>
      {% else %}
        <option value="{{ tag | handle }}">{{ tag }}</option>
      {% endif %}
    {% endfor %}
  </select>
</div>

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 %}
      <div class="filters-toolbar-wrapper{% if is_filter_by_available %} filters-toolbar--has-filter{% endif %}">
        <div class="page-width">
          <div class="filters-toolbar">
            <div class="filters-toolbar__item-wrapper">
              {% if section.settings.tags_enable %}
                {% unless collection.all_tags.size == 0 %}
                  <div class="filters-toolbar__item-child">
                    <label class="filters-toolbar__label select-label" for="FilterTags">{{ 'collections.filters.title_tags' | t }}</label>
                    <div class="filters-toolbar__input-wrapper select-group">
                      <select class="filters-toolbar__input hidden" name="FilterTags" id="FilterTags" aria-describedby="a11y-refresh-page-message a11y-selection-message" data-select-input>
                        <option value="{{ collection.url }}">{{ 'collections.filters.all_tags' | t }}</option>
                        {% for tag in collection.all_tags %}
                          {%- assign new_url = tag | link_to_tag: tag | split: 'href="' | last | split: '"' | first -%}
                          <option value="{{ new_url }}"{% if current_tags contains tag %} selected="selected"{% endif %}>{{ tag }}</option>
                        {% endfor %}
                      </select>
                      {% include 'icon-chevron-down' %}
                    </div>
                  </div>
                {% endunless %}
              {% endif %}

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

Accepted Solution (1)
Amarjyoti
Excursionist
23 10 25

This is an accepted solution.

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 -%}
  <option value="{{ new_url }}"{% if current_tags contains tag %} selected="selected"{% endif %}>{{ tag }}</option>
  {% endunless %}
{% endfor %}

 
Let me know if this works.

Thank you!!

Amarjyoti | I'm here to help and share some insights. Not looking for work.
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution

View solution in original post

Replies 7 (7)

Amarjyoti
Excursionist
23 10 25

Hey @Anne-Marieke,

Replace this:

{% for tag in collection.all_tags %}
    {%- assign new_url = tag | link_to_tag: tag | split: 'href="' | last | split: '"' | first -%}
    <option value="{{ new_url }}"{% if current_tags contains tag %} selected="selected"{% endif %}>{{ tag }}. </option>
{% 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 -%}
  <option value="{{ new_url }}"{% if current_tags contains tag %} selected="selected"{% endif %}>{{ tag | split: '_' | last }}</option>
  {% endif %}
{% endfor %}


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

Thank you!! 

Amarjyoti | I'm here to help and share some insights. Not looking for work.
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
Anne-Marieke
Excursionist
42 1 4

@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. 

 

Amarjyoti
Excursionist
23 10 25

This is an accepted solution.

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 -%}
  <option value="{{ new_url }}"{% if current_tags contains tag %} selected="selected"{% endif %}>{{ tag }}</option>
  {% endunless %}
{% endfor %}

 
Let me know if this works.

Thank you!!

Amarjyoti | I'm here to help and share some insights. Not looking for work.
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
Anne-Marieke
Excursionist
42 1 4

@Amarjyoti Yess, thank yóu! That did the trick ^_^ 

evaca
Tourist
5 0 3

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

playcode3
Tourist
9 0 2

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 

You can not solve your problems with the same level of thinking that created them.
Blakonik
Excursionist
13 0 4

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

 

I am using Publisher 2.0 theme.

Thank you,

DeAnne