Support » Fixing WordPress » How to display ALT text of featured image?

  • Resolved Advanced SEO


    I managed to show title, caption and description of featured image in post with:

    echo get_post(get_post_thumbnail_id())->post_title;
    echo get_post(get_post_thumbnail_id())->post_excerpt;
    echo get_post(get_post_thumbnail_id())->post_content;

    But, how to show image alt (“Alt Text”) of featured image?

    Best regards.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator keesiemeijer



    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”?

    Moderator keesiemeijer



    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

    Adding alternative text (alt text) in WordPress

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to display ALT text of featured image?’ is closed to new replies.