How can I hide empty metafields on my website?

Topic summary

A Shopify user is struggling to hide empty metafields from displaying on product pages, specifically wanting to hide 4 collapsible rows and 2 icons when no metafield data exists.

Initial Solution Provided:

  • Add an if statement in the main-product.liquid file
  • Wrap the collapsible tab block code with {% if block.settings.content != blank or block.settings.page.content != blank %}
  • Close with {% endif %}

Complications:

  • The solution hides both empty AND filled metafields
  • User needs multiple collapsible rows (more than one)
  • Metafields are using “rich text” type rather than “text” type, which may be causing the issue

Extended Question:
Another user successfully applied this method to products and asks how to implement the same logic for collections templates, specifically:

  • How to hide individual collapsible rows inside a content section when their metafields are empty
  • How to hide the entire collapsible content section if all metafield rows are empty

Status: The discussion remains open with unresolved questions about rich text metafields and collection-level implementation.

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

Greetings

I’m trying to solve this for hours now, but i can’t do it. I have tried all the guides here in the community on this topics but non of those work with the newest this one https://community.shopify.com/c/technical-q-a/metafields/m-p/2072928#M127871 . I want to hide 4 collapsable rows and 2 icons with text when they are empty (they do not have metafileds fill in). Does anyone knows how to do this?

Example → https://hairworkshop.gr/products/repair-senses-revitalizing-shampoo

Thanks in advance!

1 Like

Hi @mpatsi

You need to add the if statement in your main-product.liquid

  1. From you Admin page, go to Online store > Themes > Click the three dots on the theme you want to edit > Edit code

  2. Go to Section folder and open the main-product.liquid file

  3. Look for the {%- when ‘collapsible_tab’ -%}

  4. Add the if statement, and the endif at the end

{% if block.settings.content != blank or block.settings.page.content != blank %}

See image for placement

Thanks for helping!..but this hide also and the filled matafields.

Also i want to have more than 1 collaps rows..can this be possible?

If you use the dynamic metafield to fill the block content, then the code should works. If you want more than 1 row, simply add another block

The block in metafileds is richtext…can this be the problem?

How are you adding the metafield?

At the buttom of each product

Maybe the problem is here?

I have text type and not content

This worked for me perfectly with metafields in main ‘product’ liquid as suggested for empty collapsible tabs. Thank you !

Is there a way to do this for the 'collections’ template and collections metafields too? (specific area of code or in custom liquid)

I have a collapsible content section with a couple of collapsible rows with empty field issues too:

  • how do I hide the entire collapsible collection content section (if all the metafield rows are empty)

or

  • how do I hide the collapsible rows inside that section if one or all of their metafields are empty ?

Eds codes suggests something like this (with of course, the correct metafield info right after ‘unless’) :