The original code is working, it’s just set to return the Image ID instead of Object, so the alt text is not being picked up. You can see the page at with the original code.
I know there is alt text on every image because we went through and spent 6 hours adding it to the whole site ha. Also, on the ACF edit page, when I click the image, you can see our alt text.
No dice. Thanks for trying though!
Thanks…
So I tried it both ways, but maybe I’m not understanding the second part (getting the alt text to work).
I tried
<?php get_header(); ?>
<div id="gallery-content">
<h1><?php the_title(); ?></h1>
<p><?php the_field('gallery_info'); ?></p>
<?php if(get_field('gallery_images')): ?>
<?php while(the_repeater_field('gallery_images')): ?>
<?php $image = wp_get_attachment_image_src(get_sub_field('image', false), 'gallery'); ?>
<?php $image2 = wp_get_attachment_image_src(get_sub_field('image', false), 'full'); ?>
<a href="<?php echo $image2[0]; ?>" rel="shadowbox[gallery]"><img class="gallery-images" src="<?php echo $image[0]; ?>" alt="<?php echo $image[βaltβ]; ?>β /a>
<?php endwhile; endif; ?>
And
<?php get_header(); ?>
<div id="gallery-content">
<h1><?php the_title(); ?></h1>
<p><?php the_field('gallery_info'); ?></p>
<?php if(get_field('gallery_images')): ?>
<?php while(the_repeater_field('gallery_images')): ?>
<?php $image = wp_get_attachment_image_src(get_sub_field('image', false), 'gallery'); ?>
<?php $image2 = wp_get_attachment_image_src(get_sub_field('image', false), 'full'); ?>
<a href="<?php echo $image2[0]; ?>" rel="shadowbox[gallery]"><img class="gallery-images" src="<?php echo $image[0]; ?>" $alt = get_post_meta(get_sub_field(image), '_wp_attachment_image_alt', true); ?>β /a>
<?php endwhile; endif; ?>
Both options give code links instead of images on the gallery page. Can you see something I’m doing wrong? Thanks!
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.