Galen Gidman is a front-end and WordPress developer from Missouri. He runs BrandColors, ThemeBright, and he used to have a podcast. He infrequently writes about the web here.
Galen is current accepting work architecting maintainable, scalable front-end systems and WordPress-as-a-CMS builds.

Hire Galen

Getting a Image Size URL from the Advanced Custom Fields Image Field

Posted on March 14, 2014 / 10 Comments

On a recent WordPress project, I often found myself needing to get an image size URL an image uploaded via Advanced Custom Field’s image field.

The ACF image field allows you to return either the URL of the full-sized image, the image (attachment) ID, or the image object. How you configure this will depend on the method you intend to use to retrieve the URL.

Using wp_get_attachment_image_src

For this method, you’ll want to return the image ID. To get the image URL, we’ll use the following code:

Using the Image Object

You can also configure ACF to return the image object and extract the image URL like so:

10 Comments

In case someone else has this problem: I had a repeater field and needed to use get_subfield() instead of get_field(). It might have been more obvious if I wasn’t a noob, but took forever to figure that out.

Awesome… I looked everywhere for the best way to input URLs WITH image size support. Being able to use a set size instead of the default URL speeds up my pages like crazy. Thanks for the breakdown.

Thanks for that! It worked. Was wondering if it were possible to write it as a helper function. Then you can call this function to get the image for it’s respected field.

Leave a Reply

Your email address will not be published. Required fields are marked *