I use this code to display featured image title, caption (excerpt), description (content):

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 check if there is any of those fields first?

For example, how to check if there is caption, and if emty to show some other text?

Best regards.

2 Answers 2


It's more a programming question, but try this:

$post = get_post( get_post_thumbnail_id() );
if ( !isset( $post->post_title ) ) {
    echo 'Sorry no title';
} else {
    echo $post->post_title;

Use if statements.

if($caption = get_post(get_post_thumbnail_id())->post_excerpt){
echo $caption;
//echo something else

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.