Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hello, novice here.
For products which have product tags, I want to show the text: "Related keywords: [Tag1], [tag2], [tag3] ..."
I've managed to get the tags to show up on the product page. However, for products which do not have product tags it just says "Related keywords:"
In Liquid, how do I write an if statement that essentially says "Only show the following if there is a value in the Product Tag field, otherwise show nothing"?
Below is what I have so far. Appreciate your help!
Page with product tags: https://earthtoplanet.com/collections/cartoons/products/abundance-of-caution
Page with no product tags: https://earthtoplanet.com/collections/cartoons/products/pythagoras-shortcut
(Theme: Dawn)
{% if product.tags %}
<div class="product_tags">
<font size="-1.5">
Related Keywords:
</font>
{% for tag in product.tags %}
<a class="link" href="/collections/all/{{ tag | handle }}" rel="tag" style="text-decoration: none">
<font size="-1.5">
<span>{{ tag }},</span>
</font>
{% unless forloop.last %}
{% endunless %}
</a>
{% endfor %}
</div>
{% else %}
{% endif %}
Solved! Go to the solution
This is an accepted solution.
Please replace your code with the below code
{% assign tag_found = product.tags %}
{% if tag_found != blank %}
<div class="product_tags">
<font size="-1.5">
Related Keywords:
</font>
{% for tag in product.tags %}
<a class="link" href="/collections/all/{{ tag | handle }}" rel="tag" style="text-decoration: none">
<font size="-1.5">
<span>{{ tag }},</span>
</font>
{% unless forloop.last %}
{% endunless %}
</a>
{% endfor %}
</div>
{% endif %}
If helpful then please Like and Accept Solution. Want to modify or custom changes on store Hire me. Feel free to contact me on mail | Shopify Design Changes | Custom Modifications In to Shopify Theme
This is an accepted solution.
Please replace your code with the below code
{% assign tag_found = product.tags %}
{% if tag_found != blank %}
<div class="product_tags">
<font size="-1.5">
Related Keywords:
</font>
{% for tag in product.tags %}
<a class="link" href="/collections/all/{{ tag | handle }}" rel="tag" style="text-decoration: none">
<font size="-1.5">
<span>{{ tag }},</span>
</font>
{% unless forloop.last %}
{% endunless %}
</a>
{% endfor %}
</div>
{% endif %}
If helpful then please Like and Accept Solution. Want to modify or custom changes on store Hire me. Feel free to contact me on mail | Shopify Design Changes | Custom Modifications In to Shopify Theme
Ah hah! !=blank was the term I was looking for. Thank you!
Out of curiosity, why do I need to begin with
{% assign tag_found = product.tags %}
{% if tag_found != blank %}
Wouldn't it work with just:
{% if product.tags != blank %}
Sometimes direct comparison doesn't work so we have to assign it to a variable and then compare.
Hope your issue has been resolved
Please like and accept as solution to help other peoples.
Thank you!
Thank you for this, I have this installed and working on my site.
I would also like to create a collection for the 'Product Type' and/or the 'Product Category'. Would you be able to supply the code for that?
Thanks,
Mike
Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025Discover opportunities to improve SEO with new guidance available from Shopify’s growth...
By Jacqui May 1, 2025