Display Alt Text under a Post Thumbnail
-
I got captions to load under thumbnail images with mosdave’s function posted here: Display caption with the_post_thumbnail (this thread is now closed).
Mosdave’s code works fine for displaying the title, caption, or description, but it won’t display the alt text, as suggested in the last lines.
Mosdave’s function is here:
function the_post_thumbnail_caption() { global $post; $thumb_id = get_post_thumbnail_id($post->id); $args = array( 'post_type' => 'attachment', 'post_status' => null, 'post_parent' => $post->ID, 'include' => $thumb_id ); $thumbnail_image = get_posts($args); if ($thumbnail_image && isset($thumbnail_image[0])) { //show thumbnail title echo $thumbnail_image[0]->post_title; //Uncomment to show the thumbnail caption //echo $thumbnail_image[0]->post_excerpt; //Uncomment to show the thumbnail description //echo $thumbnail_image[0]->post_content; //Uncomment to show the thumbnail alt field //$alt = get_post_meta($thumbnail_id, '_wp_attachment_image_alt', true); //if(count($alt)) echo $alt; } }
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
The topic ‘Display Alt Text under a Post Thumbnail’ is closed to new replies.