Try it with this:
$thumbnail = get_post( get_post_thumbnail_id() );
echo $thumbnail->post_title;
echo $thumbnail->post_excerpt;
echo $thumbnail->post_content;
echo get_post_meta( $thumbnail->ID, '_wp_attachment_image_alt', true );
Thank you, it works.
I found similar solution just before your answer like this:
$thumb_img = get_post_meta( get_post_thumbnail_id() ); // Get post ID
echo $thumb_img['_wp_attachment_image_alt']['0']; echo '<br />';// show alt text
I need more help 🙂
How to display image file name, with or without extension (bare image name), format?
I asked for this here:
Also, can you make another function to check if there is alt text at all, and if there is to show it, and if there is no alt text to echo “some other text”?
Try this for the alt text
$alt_text = get_post_meta( $thumbnail->ID, '_wp_attachment_image_alt', true );
if( !empty( $alt_text )){
echo $alt_text;
} else {
echo 'no alt text found';
}
Thank you, but now in both cases (with or without alt) I get “no alt text found”?
Am I doing something wrong?
i would love if you and your readers can read my article on “adding alternative Text, Hyperlinks, giving photo-credits” i would love to see your feedback. and Yeh it also contains a video i uploaded, just for better understanding 🙂
Visit my blog and do give your feedback
http://www.thenextrex.com/alternative-text-or-alt-text-in-wordpress/