Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add the following Liquid snippet to a product template (Sections/product-template.liquid) to show tags on a Shopify product page. The tags will correctly link back to the current product collection with the tag filters applied.
{% if product.tags %}
{% if collection.handle %}
{% assign collection_scope = collection.handle %}
{% else %}
{% assign collection_scope = 'all' %}
{% endif %}
<ul class="product-tags">
<li>Tags: </li>
{% for tag in product.tags %}
{% capture url %}/collections/{{ collection_scope }}/{{ tag | handleize }}{% endcapture %}
<li>{{ tag | link_to: url }}</li>
{% endfor %}
</ul>
<style media="screen">
ul.product-tags {
list-style-type: none;
margin: 0;
padding: 0;
}
ul.product-tags li {
display: inline-block;
font-weight: bold;
text-transform: uppercase;
letter-spacing: 1px;
font-size: 12px;
}
ul.product-tags li a {
text-decoration: none;
}
</style>
{% endif %}
@jonathanmoore
Copy link
Author

jonathanmoore commented Jun 26, 2017

This was written specifically for the District theme however it should work for any Shopify theme.

@ahsonRaza
Copy link

ahsonRaza commented Aug 31, 2018

Hi Jonathan, I have a question as i have been searching this and found nowhere the required answer, can you please help me to find a way to add / assign tag to a product through liquid?
I mean i want to give some specific products some specific tags, as there are thousands of products in a store and doing it manually will take days to add the tags, i want something like this
{% if product.price >1 or <75 %}
{% assign tag="less-than-75" %}
{% else %}
{% assign tag="above" %}
{% endif %}

Please ignore the coding error as i am totally new to the shopify liquid
Thanks in advance
Any help will be appreciated

@jinesh24
Copy link

jinesh24 commented Nov 10, 2018

Hi Jonathan, I have a question as i have been searching this and found nowhere the required answer, can you please help me to find a way to add / assign tag to a product through liquid?
I mean i want to give some specific products some specific tags, as there are thousands of products in a store and doing it manually will take days to add the tags, i want something like this
{% if product.price >1 or <75 %}
{% assign tag="less-than-75" %}
{% else %}
{% assign tag="above" %}
{% endif %}

Please ignore the coding error as i am totally new to the shopify liquid
Thanks in advance
Any help will be appreciated

I think this free app will save hours of your time
https://apps.shopify.com/power-tools-bulk-edit-tags

@telanpo
Copy link

telanpo commented Jun 9, 2021

This was written specifically for the District theme however it should work for any Shopify theme.

thanks a lot jonathanmoore, i used it on the Simple theme and it works great, a little styling and its fine. As i am new to shopify liquid staff, i called a render command on the new liquid file i created from your code and added it on the bottom of the product template.
Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment