PHP WordPress

Display caption with post thumbnail in WordPress


    $caption = get_post( get_post_thumbnail_id() )->post_excerpt;

    if ( $caption != "" ): ?>
            <?php echo $caption; ?>
    <?php endif; ?>

2 replies on “Display caption with post thumbnail in WordPress”

Morten I updated the post. Caption is displayed only if it is not empty.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.