<figure> <?php the_post_thumbnail(); $caption = get_post( get_post_thumbnail_id() )->post_excerpt; if ( $caption != "" ): ?> <figcaption> <?php echo $caption; ?> </figcaption> <?php endif; ?> </figure>
<figure> <?php the_post_thumbnail(); $caption = get_post( get_post_thumbnail_id() )->post_excerpt; if ( $caption != "" ): ?> <figcaption> <?php echo $caption; ?> </figcaption> <?php endif; ?> </figure>
2 replies on “Display caption with post thumbnail in WordPress”
how do you tjek for if figcaption is empty
Morten I updated the post. Caption is displayed only if it is not empty.