Remove metafied when there is no text for it

Hi!

can´t seem to fix it. Already watched the other question about it but after 3 hours im giving up. I want to remove the metafields when they are blank. Thanks for any help!

Hello @NewSkinOrder23

You can make modifications to the theme’s code Here is a step-by-step guide:

  1. Online Store > Themes

  2. Click the “Actions” button, then select "Edit code.

You’ll need to locate the code that displays the metafields and add a condition to check if they are blank before rendering them. Follow these steps:

  1. Under “Sections,” click on “article-template.liquid” to open the blog post template file.

  2. The section of code that displays the metafields. It might look something like this.

{% if article.metafields.your_metafield_key %}
  

{{ article.metafields.your_metafield_key }}

{% endif %}
  1. Modify the code to include a condition that checks if the metafield is blank before rendering it. You can use the blank? filter to check if the value is empty.

Here’s an example:

{% if article.metafields.your_metafield_key | blank? != true %}
  

{{ article.metafields.your_metafield_key }}

{% endif %}

This code checks if your_metafield_key metafield is not blank before displaying it.

  1. Repeat the above steps for any other metafields that you want to remove when they are blank.

  2. Save the changes to the file.

After saving the changes, the metafields that are blank should no longer be displayed in your Shopify Symmetry theme.

The specific implementation may vary depending on the structure and customization of your theme.

The above steps are a general guide, and the actual code and file names may be different in your theme.

1 Like

Thanks for the reply! I just cant seem to find where that code is located…

I dont have article-template, and for some reason i cant send screenshots because png or jpg is not supported?

Hello @NewSkinOrder23

you may need to locate and modify the relevant code in a different file. Here’s an alternative approach:

  • “templates/article.liquid”: This file controls the layout of individual blog post pages.
  • “sections/blog-template.liquid”: This file is responsible for the blog post listing page.

Hello @NewSkinOrder23

Try for the “featured-blog.liquid”

Cant see anything about metafields here either..