I am using an attachment.php file to show large versions of images that have been clicked on elsewhere. I'd like to pull the image alt text as a caption under the image with javascript, but the alt text isn't included when when wp_get_attachment_image_src() is used. I don't think WP has a function to retrieve it, so I need my own. To write that function I need to know...Where is the alt text for an image stored?
My attachment page uses wp_get_attachment_image_src()
, which doesn't include the alt text.
<div class = "entry">
<?php
if ( wp_attachment_is_image( $post->id ) ) :
$att_image = wp_get_attachment_image_src( $post->id, "large");?>
<a href="<?php echo wp_get_attachment_url($post->id); ?>"
title="<?php the_title(); ?>"
rel="attachment">
<img class="attached_img"
src="<?php echo $att_image[0];?>"
width="<?php echo $att_image[1];?>"
height="<?php echo $att_image[2];?>"
class="attachment-medium"
alt="<?php $post->post_excerpt; ?>" />
</a>
} <?php endif;?>
</div>
This shows:
<div class = "entry">
<a href="http://www.example.com/wp-content/uploads/2010/07/photo_namejpg"
title="My_Photo_Title"
rel="attachment">
<img class="attached_img"
src="http://www.example.com/wp-content/uploads/2010/07/photo_name_and_size.jpg"
width="393"
height="500"
class="attachment-medium"
alt="" />
</a>
</div>
I'm aware that the $post->post_excerpt
is being called in the above code, but I am not sure what to replace it with to get the image's alt attribute.