Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
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.
Solved! Go to the solution
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!!
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 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.
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!!
Can you please let us know where did you place the code? Please and thanks!
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
By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024