Home Forums Front-end Issues image not showing correctly Reply To: image not showing correctly

  • hi @kiouv

    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[1]; ?>" height="<?php echo $image_dimensions[2]; ?>" />

    hope it could help you.