Shopify themes, liquid, logos, and UX
Hello,
How can I hide a section in product page when metafield is empty?
(1) I wanna add an image in product page by using slideshow section with dynamic source {{product.metafields.custom.imagebanner}}. However, for products that don't have metafield value, it shows the section template on website which looks weird. Is there anything I can do to hide the entire section for certain products if their metafield is empty?
^ what it shows when metafield is empty.
Besides, (2) I also tried to use custom liquid section, but I got another problem is that the image display is not responsive. It cropped the image when viewing from mobile or smaller devices
The code I tried:
{% if product.metafields.custom.imagebanner != blank %}
<p style="text-align: center;">{{product.metafields.custom.imagebanner | image_url: width: "600" | image_tag}}</p>
{% endif %}
^ image cropped on mobile devices.
Much appreciated if you can solve either (1) or (2). Thank you in advance!
Hello @AMSTG ,
Here is some suggestions you can try to take:
{% if product.metafields.custom.imagebanner != blank %}
<!-- Slideshow section code goes here -->
{% endif %}
img {
max-width: 100%;
height: auto;
}
Save and preview.
Hope this can help.
Ali Reviews team.
Thanks for your reply. I tried both solutions but they don't work. Did I place the codes correctly?
(wrap the section with if codes)
^ Did I place the codes at the right place? It doesn't allow me to save.
(make image responsive)
^ added at the bottom of template-collection.css, but the image is still cropped in mobile view.
If you're still looking for a solution—or if anyone else is facing the same issue—I recently made a tutorial on how to hide sections, blocks, or tabs dynamically in Shopify when a metafield is empty. Instead of displaying blank fields, you can use a simple Liquid condition to ensure only relevant information appears on each product page.
Check out the video here: https://youtu.be/lmwSaVsbAB0
Hope this helps! Let me know if you have any questions.
Hey Community 👋 Did you know that March 15th is National Everything You Think Is W...
By JasonH Apr 1, 2025Discover how to increase the efficiency of commerce operations with Shopify Academy's l...
By Jacqui Mar 26, 2025Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025