fbpx
How to Show WordPress Featured Image Caption Without a Plugin

How to Show WordPress Featured Image Caption Without a Plugin

This WordPress snippet will allow you to show the image caption for the featured image in your WordPress posts without using a plugin.

Instructions
Add this code to your theme files (ie. single.php) where you are displaying the image.
ur image.

<?php if (get_post( get_post_thumbnail_id())->post_content);  // check if image has caption added ?>
     <div class="featured_image_caption">
          <?php echo wp_kses_post(get_post( get_post_thumbnail_id() )->post_content ); // outputs image caption ?>
     </div>
<?php endif; ?>

*you can replace post_excerpt with post_content to get the image description etc.

WordPress Snippet Info

Tested with Wordpress v. 4.9.5
Last Modified: 24.11.2018
Last Reviewed: 24.11.2018

How to Show WordPress Featured Image Caption Without a Plugin
3.5 (70%) 14 vote[s]
Please report broken snippets.
Report Broken Snippet
WordPress Hosting

Recent Comments