Why are my hidden empty meta fields showing again?

Topic summary

Main issue: Empty product metafield sections (ingredients/shipping/how-to) reappeared after a JS-based hide script stopped working.

Key context: Store uses Dawn theme. Metafields are linked via the Theme Editor (collapsible tabs). Initial approach injected a script in theme.liquid to remove empty accordion content; it worked briefly, then failed.

Proposed resolution: Use Liquid (server-side) instead of JavaScript. Wrap the collapsible_tab block output in main-product.liquid with a conditional so empty content doesn’t render.

Implementation details:

  • In main-product.liquid, within the case for collapsible_tab, surround the block with:
    {% if block.settings.content != “” %} … {% endif %}
  • The earlier suggestion using != null didn’t work because the setting exists even when the metafield is empty. Checking for an empty string did.
  • Ensure the {% endif %} is placed before the next when block (e.g., quantity_selector).

Outcome: OP confirmed the Liquid solution works reliably. Guidance given that Liquid avoids load-time flicker and JS-disabled issues.

Open items: Follow-up questions on handling blocks with multiple metafields (use OR conditions) and hiding a multicolumn section based on empty metafields; no final answer provided yet.

Notes: Code snippets are central to understanding the fix.

Summarized with AI on December 28. AI used: gpt-5.

Hey

iam using Meta fields to show ingredients, shipping details and how to use the product. But for some there are no such informations i looked for a solution to hide the empty meta fields in the frontend. From a different Disscusion i found this code from this discussion Solved: How to hide blank metafields. - Shopify Community

I implemented the code and it worked perfectly fine but one day later it didnt worked but i didnt changed anthing on the code.

do you have any idea why this is happening?

1 Like

Can I ask why you’re using javascript and not liquid?
With liquid, you can wrap the html that you don’t want to show if it’s empty with an if statement -
eg:

{% if product.metafield.namespace.key != blank %}

Here is a metafield bit

{{ product.metafield.namespace.key }}

{% endif %}

If it’s one block containing multiple metafield references and you want to remove it if there is nothing there, you can just use or in the if statement
eg

{% if product.metafield.namespace.key != blank or product.metafield.namespace2.key2 != blank%}

Here is a metafield bit

{{ product.metafield.namespace.key }}

{{ product.metafield.namespace2.key2 }}

{% endif %}
This means it will only show if metafield 1 or metafield 2 (or both) exists.

First of all thank you for the Reply.

i copied the code from another solution. but i paste it into the theme.liquid area

where and how do i have ti implement ur code to check?

@Mellowsilcbd where you this code added ?

where you create the meta filed ?

I will suggest to when you rener the metafiled that time you can check with

{% if product.meta.  %} {% endif %}

Hi Mellowsilcbd,
Could you show us in your liquid file where the metafields are referenced - ie the bit where you show the ingredients
Thanks
Rhianna :slightly_smiling_face:

The code is added in the theme.liquid section

the meta field is created in products.

the script is added above the

Hi Mellowsilcbd,
No, sorry I mean in the main-product.liquid (or similar, not sure what theme you’re using) :slightly_smiling_face:
The bit on your product page where you reference the ingredients metafield :+1:

Hi Rhianna,

do you mean on the “Frontend” of the Store what the Customer sees or in the Backend in the Section Products?

if it helps iam using the Dawn Theme

Hi Mellowsilcbd,

I mean the code in shopify, not what the customer sees :slightly_smiling_face:

Not important right now, but this is all classed as ‘Frontend’ in web development haha :grinning_face_with_smiling_eyes:

That does help, thank you.
I just need to see in your code where it says {{ product.metafields. (and then what your metafield is called) }}

Hey i think iam pretty stupid right now haha but this is the only thing i can find with {{product.metafields but rating isnt what my ingridents metafield is called

Iam pretty desperate. Iam sorry iam acting so stupid right now haha

i added the metafields in the admin settings

maybe this helps

Ah okay - do you link to them in the theme editor then?

(And not stupid at all!)

yes thats exactly how i do it. the shopif support advised me to do so

Ohh yes great, so in the liquid file if you search for

{%- when ‘collapsible_tab’ -%}
I’m not sure exactly what yours will look like, as we use dawn but have made a lot of changes over time

{%- when ‘collapsible_tab’ -%}

{% if block.settings.content != null %}

*more code ..*
**{% endif %}** {%- when 'reviews-io' -%} - This might not be your next block, but you'll just want the endif before the next 'when'

You will want to add these bold bits in :slightly_smiling_face:

First Thank you very much.

i just have to ask which liquid file exactly do you mean?

Hi Mellowsilcbd,

In the main-product.liquid file :slightly_smiling_face:

Thank you very much so now it should look like this?

Just move that {% endif %} down two lines, so it is above the {% when ‘quantity_selector’ %} :slightly_smiling_face:

i changed it but sadly it isnt working :disappointed_face: