WordPress.org

Ready to get started?Download WordPress

Forums

Advanced Custom Fields
Displaying alt text for images (7 posts)

  1. rikardo85
    Member
    Posted 1 year ago #

    Hello,

    Can anyone help with adding the alt text set in the media library to the images set using the ACF plugin?

    The code I am using is

    if (get_field('image')!='')
    {
     ?>
    <img src="<?php the_field('image'); ?>" alt=""/>
    <?php
    }
     ?>

    Thanks

    http://wordpress.org/extend/plugins/advanced-custom-fields/

  2. Aleksandar Perisic
    Member
    Posted 1 year ago #

    <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.

  3. rikardo85
    Member
    Posted 1 year ago #

    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

  4. Aleksandar Perisic
    Member
    Posted 1 year ago #

    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 } ?>
  5. amucklow
    Member
    Posted 6 months ago #

    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.

  6. avexdesigns
    Member
    Posted 5 months ago #

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

  7. bboywattsy
    Member
    Posted 4 months ago #

    <?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".

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags