Advance Custom Fields retrieving alt image

How can i add to my code

<img src="<?php the_sub_field('img'); ?>"  alt="????" />

Te “alt” value of the image in my media, form my wordpress.

Related posts

Leave a Reply

1 comment

  1. Advanced Custom Fields gives you a choice of return values. Given your current code I’d guess you’ve gone with URL.

    In order to display the ALT tag you’ll need to choose object instead. ID could work too but it’s adding an extra step.

    After choosing the new return value replace your code with:

    <?php if ( $image = get_sub_field( 'img' ) ) {
        printf( '<img src="%s" alt="%s" />', $image['url'], $image['title'] );
    } ?>