I have used wp_get_attachment_image_src to display my images – I’m doing it this way as I need to use the image’s caption (post_excerpt) as my ‘alt’ content. Frustratingly (for me with limited experience!) timstl code works only when using wp_get_attachment_image. With this in mind how would I change timstl’s snippet so it works form me also? Here’s what I’m working with…
<?php if(get_field('post_images')): ?> <?php while(the_repeater_field('post_images')): ?> <?php $image = wp_get_attachment_image_src(get_sub_field('post_image'), 'large'); $largeImage = wp_get_attachment_image_src(get_sub_field('post_image'), 'full'); $attachment_id = get_post_thumbnail_id($post_id); ?> <li <?php the_sub_field('module_class');?>> <a href="<?php echo $largeImage; ?>" title="<?php $attachment = get_post($attachment_id); echo($attachment->post_excerpt); ?>"> <img src="<?php echo $image; ?>" alt="<?php $attachment = get_post($attachment_id); echo($attachment->post_excerpt); ?>" /></a></li> <?php endwhile; ?> </ul> <?php endif; ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
The ACF site is currently experiencing some issues.— Advanced Custom Fields (@wp_acf) September 21, 2022
We apologize for the inconvenience and we are working hard to get it back up and running as soon as possible.
© 2022 Advanced Custom Fields.