Alicia Ramirez

Advanced Custom Fields Image Object Tutorial

Update (10/11/2016): I added some escaping to the examples. Better safe than sorry.

When creating an image custom field in Advanced Custom Fields, it gives you the option of setting the “Return Value” as an “Image Object”.

Advanced Custom Field Adding an Image Screen

If you choose the “Image Object”,  get_field() will get a multidimensional array with all of the image’s values in it (instead of just the URL for the full size version, or the attachment ID), which will look something like this:

As you can see, this is a lot of information, which means, power! You can now use all that information to properly display that image in your templates.

To get a specific value, for example the ‘alt’, and ‘thumbnail’ size, you would have the following code:

If, for example, you wanted to do a lightbox with your images, you would do this:

Exit mobile version