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

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:

9 thoughts on “Getting a Image Size URL from the Advanced Custom Fields Image Field

  1. 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.

  2. 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.

  3. 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.

Share Your Thought