Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
I created a new metaobject since none of the listed store areas like Products, variants and so on in Shopify admin fit my requirement. The metaobject I created contains two fields as seen in the image below.
I want to know how to read these fields in header.liquid.
I need to change site's header logo often and want to make it automated with a cronjob that runs on a different server that populates these fields once a day with the logo file name.
Solved! Go to the solution
This is an accepted solution.
To read the fields from your custom metaobject in the header.liquid
file, you'll need to use Shopify's Liquid language and access the metafields associated with the current shop.
Here's an example of how you can retrieve and display the values of the custom metaobject fields in your header:
{% assign shop_metaobject = shop.metafields.custom.my_metaobject_key %}
{% if shop_metaobject %}
{% assign logo_file_name = shop_metaobject.logo_file_name %}
{% assign logo_alt_text = shop_metaobject.logo_alt_text %}
<img src="{{ logo_file_name }}" alt="{{ logo_alt_text }}" />
{% endif %}
This is an accepted solution.
To read the fields from your custom metaobject in the header.liquid
file, you'll need to use Shopify's Liquid language and access the metafields associated with the current shop.
Here's an example of how you can retrieve and display the values of the custom metaobject fields in your header:
{% assign shop_metaobject = shop.metafields.custom.my_metaobject_key %}
{% if shop_metaobject %}
{% assign logo_file_name = shop_metaobject.logo_file_name %}
{% assign logo_alt_text = shop_metaobject.logo_alt_text %}
<img src="{{ logo_file_name }}" alt="{{ logo_alt_text }}" />
{% endif %}
Thank you. Can you tell me what is difference between metaobject and metafields as I see them both in Shopify admin?
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025