How to display text only for products with tags in Liquid?

Topic summary

A Shopify developer needed to conditionally display product tags on product pages, showing \

Summarized with AI on November 12. AI used: claude-sonnet-4-5-20250929.

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 %}
              
                
                
                  
                  Related Keywords:
                
               {% for tag in product.tags %}
       
                 
                   
                     {{ tag }},
                   
                   {% unless forloop.last %}
                   {% endunless %}
                
               {% endfor %}
           
              

             
              {% else %}
              {% endif %}
1 Like

@earthtoplanet

Please replace your code with the below code

{% assign tag_found = product.tags %}
        {% if tag_found != blank %}

        

          
            Related Keywords:
          
          {% for tag in product.tags %}

          
            
              {{ tag }},
            
            {% unless forloop.last %}
            {% endunless %}
          
          {% endfor %}

        

        {% 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 %}

@earthtoplanet

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.

1 Like

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