Get images alt tag and display
-
I am trying to get the alt tag from images uploaded as attachments and display it. Currently my code finds the images and places them in a container ( a slideshow ) but I can’t get the alt tags to show up..
<div class="project-slide-holder clearfix"> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID ); $attachments = get_posts( $args ); if ( $attachments ) { foreach ( $attachments as $attachment ) { echo ''; echo wp_get_attachment_image( $attachment->ID, 'project-page-image' ); echo ''; } } ?> </div> <div class="project-caption"> <p><strong class="blue"><?php the_title(); ?> <span class="image-descript"> <?php $alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true); if(count($alt)) echo $alt;?> </span></p> </div> <?php endwhile; endif; ?>
Any ideas? Im not sure why it isn’t showing up at all?
- The topic ‘Get images alt tag and display’ is closed to new replies.