Support

Account

Home Forums General Issues Get ALT tag for image inside repeater

Solving

Get ALT tag for image inside repeater

  • Hello,

    Can someone explain how to pull the ALT tag for an image inside the repeater?

    This is the block I am working with.

    <?php while(the_repeater_field('banner')): ?>
    <div>
        <h1><?php the_sub_field('heading'); ?></h1>
        <p><?php the_sub_field('description'); ?></p>
        <img src="<?php the_sub_field('image'); ?>" alt="">
    </div>
    <?php endwhile; ?>
  • I think I figured it out. I was using ‘Image URL’ and needed to switch to ‘Image Array’ and change the code to the following. If someone could confirm I’m doing this correctly that would be great.

    <?php while(the_repeater_field('banner')): ?>
    <?php $image = get_sub_field('image'); ?>
    <div>
        <h1><?php the_sub_field('heading'); ?></h1>
        <p><?php the_sub_field('description'); ?></p>
        <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>">
    </div>
    <?php endwhile; ?>
  • Hi @wyclef

    Yes, your method is correct. Kindly check this page to learn more about the image field: https://www.advancedcustomfields.com/resources/image/.

    Thanks 🙂

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

You must be logged in to reply to this topic.