if your field return an array it’s because you set it to return an array.
on the ACF image field settings there is an option that you can change its returnable value.
go to the image field and take a look there, you will find your answer. you should set it to return image URL. so your code should be like this in your template:
<img src="<?php the_field( 'image_field_name' ); ?>" />
to get image dimensions, title, caption, description you should go a little more advanced.
let’s get the things we need:
$image_dimensions = wp_get_attachment_image_src( get_field( 'image_field_name', false, false ), 'full' ); $image_meta = get_post( get_field( 'image_field_name', false, false ) ); $image_alt = get_post_meta( $image_meta->ID, '_wp_attachment_image_alt', true );
‘full‘ => it define the image size. EX: full, thumbnail, small, … ( it’s in your theme function and could be more )
‘_wp_attachment_image_alt‘ => it get image alt, the italic part could be caption, description.
so your template code should looks like this:
<img src="<?php the_field( 'image_field_name' ); ?>" alt="<?php echo $image_alt; ?>" width="<?php echo $image_dimensions; ?>" height="<?php echo $image_dimensions; ?>" />
hope it could help you.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
The ACF site is currently experiencing some issues.— Advanced Custom Fields (@wp_acf) September 21, 2022
We apologize for the inconvenience and we are working hard to get it back up and running as soon as possible.
© 2022 Advanced Custom Fields.