Hiding metafields in blog posts when empty

1 0 1

Hi all, I've spent hours trying to hide metafields in *blog posts* when they are empty and I can't get anything to work. 

I want to add metafields for a featured product and a featured collection at the end of my blog posts: but I want to hide them when they're not assigned. I've set up the metafields (blog-product and blog-collection). 

I've watched/read several solutions and haven't gotten any to work. The following one responded, but hides ALL metafields - whether they're assigned or not: 


{% if collection.metafields.custom.blog-product == blank %}

{display: none;



{% endif %}


Screenshot 2024-03-24 at 6.56.52 PM.png


As you can see, I added them within the shop editor on the "blog post" settings. 

Does anyone have any solutions for this? It's a handy feature, if I can get it to display only when it's populated 🙂 

Reply 1 (1)

Shopify Partner
723 92 112



i suggest you to do not display none make a condition like below that if the field is empty there will be nothing to show.


{% if collection.metafields.custom.blog-product == blank %}

{% else %}

{{ collection.metafields.custom.blog-product }}

{% endif %}

OR 2nd Condition will be

{% if collection.metafields.custom.blog-product != blank %}

{{ collection.metafields.custom.blog-product }}

{% endif %}



- Please don't forget to Like and Mark Solution to the post that helped you. Thanks!
- Your Shopify Solution Specialist For further discussion contact: Email ID- Liqud_3xPert_SJ OR Whatsapp
- Buy a Coffee for me to get more frequently help 🙂
- Hire Me to unlock the full potential of your e-commerce store Now 🙂