Viewing 6 replies - 1 through 6 (of 6 total)
  • <img src="<?php the_field('image'); ?>" alt="<?php the_field('image_alt'); ?>"/>

    the easiest one is to create one more field where u will put alt text.

    Thread Starter rikardo85

    (@rikardo85)

    Thanks.

    You suggestion above is what I normally do. But taking on a site that has many images set, it will take me ages to add in the alt field in the dashboard.

    thanks again

    Can u try this solution my friend:

    <?php
    
    $image = get_field('image' );
    
    ?>
    <p>The url is: <?php echo $image['url' ]; ?>, the title is <?php echo $image['title' ]; ?> and the alt is: <?php echo $image['alt' ]; ?></p>
    <?php if( get_field('image') ) {
    $image = get_field('image' ); ?>
    <img class="span6 pull-left"
    src="<?php echo $image['url']; ?>"
    alt="<?php echo $image['alt']; ?>">
    <?php } ?>

    The best way is not to add further fields, but instead to select ‘Image Object’ in the return value. That way you get an array of all the image data from the media library.

    avexdesigns

    (@avexdesigns)

    I’m trying to figure this out as well. Can anyone help??

    <?php if( get_field('image_1') ) {
    $image = get_field('image_1' ); ?>
    <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>">
    <?php } ?>

    Change image_1 to your specific Field name and in the Custom Fields Edit Field Group section for the image field set the return value to “Image Object”.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Displaying alt text for images’ is closed to new replies.