Home Forums Front-end Issues Outputting image title


Outputting image title

  • Hi,

    First of all, I would like to thank you for this great plugin, it’s really helpfull for WordPress development.

    I have a problem that I can’t solve :
    I have a subfiled named ‘photos’ in which I can add one or several images uploaded from WordPress.
    I reach to display the image recovering the url (see the code below) but I can’t find a way to display the ‘title’ or ‘alt’ or ‘description’ of the image!!
    Can you help me find the solution please ?

    Here is my code :

    <?php if(get_field('diaporama')){ ?>
    <?php while(the_repeater_field('diaporama')): ?>
    <img src="<?php the_sub_field('photos'); ?>"/>
    <?php endwhile; ?>
    <?php } ?>

    Thanks in advance for your time.

    P.S : sorry for my bad english, I’m from france 🙂

  • This will do it:

          $image = get_sub_field('photos');
          $image_full = $image['sizes']['large'];
          $alt = $image['title']; ?>
          <div class="col-split">
           <a class="fancybox" rel="gallery1" href="<?php echo $image_full; ?>">
           <img class="img_cen" src="<?php echo $image_thumb; ?>" alt="<?php echo $alt; ?>" title="<?php echo $alt; ?>" />
           <?php endwhile; ?>
       <?php endif; ?>
  • Hi rorymheaney,

    Thanks for your help, this is almost what I need.

    What you gave me works perfectly, but I can’t display full size image instead of large size image, even if I write that :
    $image_full = $image[‘sizes’][‘full’];

    Do you have an idea for that ?

    Thanks again !

  • Thanks rorymheaney,

    I just replaced the line :

    $image_full = $image['sizes']['large'];


    $image_full = $image['url'];

    And now everything is ok.

    Thanks for your help!

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Outputting image title’ is closed to new replies.