Unable to access ProductImage Metafield with Liquid

Shopify Partner
22 1 4

Hi Guys,


As shopify does not support China CDN anymore, we plan to build our own cdn for china customer as store the new image url in ProductImage metafield. However, when we tried to access the metafield in Liquid seems like it does not work. Is it possibly that Liquid does not have access to Product Image metafield? Because I am 100% sure that ProductImage has metafield and we have successfully added it.

Replies 2 (2)

Shopify Partner
158 32 99

Hi @Maacck ,


The thing is that the payload returned for a file/image metafield is a generic file object .

You can display an image by combining the Liquid code, an image_url filter and proper HTML <img> tag.

Instead of a single line of code like this:
{{ product.metafields.namespace.key.value }}
You may want to use a snippet like this:
{% assign image_url = product.metafields.namespace.key %}
{% if image_url != blank %} 
 <img src="{{ image_url.value | image_url }}">
{% endif %}
Check out Metafields Guru, the #1 ranked metafields app.

Bulk editor | Data import/export | Metafield sets | Browser extension
Shopify Partner
22 1 4

I was try to access the ProductImage's metafield instead of Product itself, and seems like is does not work.