Home > Shopify Development > Liquid asset_img_url How to Get Asset Image URL in Shopify

Liquid asset_img_url How to Get Asset Image URL in Shopify

Sam Nguyen
Sam Updated: May 28, 2024

Share:

Drive 20-40% of your revenue with Avada
avada email marketing

Are you struggling to find image URLs in your Shopify store? Many store owners face this challenge when managing their theme assets. This guide will show you how to get asset image URLs in Shopify using the Liquid asset_img_url filter. Whether you’re a new entrepreneur or an experienced developer, you’ll learn how to easily access and use these important resources for your online store. Say goodbye to asset management headaches and hello to smoother Shopify theme customization.

Table of content

General information about Liquid and URL filter

Liquid has been accessed to users for more than a decade and becomes a trustworthy source to upload dynamic content on the front page. Not only is it used by Shopify but Liquid is also applied on Jekyll.

Five main types of filters in Liquid are string, number, boolean, array and URL. Number includes floats and integers. Boolean response to true or false value. Nil is a special empty value that is returned when Liquid code has no results. Our main topic is URL filter.

URL filters outputs links to have access to Shopify’s content network as well as links to edit blogs or articles. Moreover, URL uses numbers, letters flash and a question mark.

Key information about asset_img_url

URL or uniform resource locator is a reference to a web resource that specifies its location on a computer network and a mechanism for retrieving it. A URL contains the following information: the protocol used to access a resource, the location of the server, the location of the resource in the directory structure, a fragment identifier.

All URLs are presented in the following order: scheme name, colon and two slashes, location of server, the location of the resource on the server, fragment identifier.

asset_img_url returns the asset of URL of an image in the folder of a theme. Besides, asset_img_url accepts size parameters. An image’s width and height is 5760 x 5760 px. The image’s original aspect ratio will be preserved unless you crop the image.

No matter what size you specify, an image can never be resized to be larger than its original dimensions.

For example:


{{ product | img_url: '450x450' }}

Sample code to get asset image URL in Shopify

Take a look at the sample to see how URL link is generated when you use the URL filer.

Input:


{{ 'logo.png' | asset_img_url: '300x' }}

Output:


//cdn.shopify.com/s/files/1/0000/0001/t/1/assets/logo_300x.png?42

Conclusion

In conclusion, mastering the asset_img_url filter in Shopify is crucial for effective theme management. This powerful tool simplifies the process of retrieving and customizing image URLs, enhancing your store’s visual appeal and performance. By applying the techniques outlined in this guide, you can streamline your workflow and create a more engaging shopping experience. Take action now: start experimenting with asset_img_url in your Shopify theme to unlock its full potential and elevate your online store’s design.


Sam Nguyen is the CEO and founder of Avada Commerce, an e-commerce solution provider headquartered in Singapore. He is an expert on the Shopify e-commerce platform for online stores and retail point-of-sale systems. Sam loves talking about e-commerce and he aims to help over a million online businesses grow and thrive.

Stay in the know

Get special offers on the latest news from AVADA.