Display Image Caption Under Featured Images In WordPress

WordPress lets you add the image caption and its description per images uploaded in your site. So, if you are building up the WordPress theme or news site, then, probably you may want to display image caption under the featured images of your site, isn’t it? Well, so you searched for the same and landed on this very page, hence you are in total luck on this. Here, we will describe about how to display image caption under the featured images of your posts.

What is image caption?

Well, the answer to this is, it is just the small bit of information about what the image is for. Also, the main advantage of this in WordPress sites is, it can be utilized to display about the image license in the WordPress posts, which is especially greatly helpful for the news/magazine sites.

Also, just lets us say that, you have an important image added in your site and hence want to display about where it is taken, right? Well, you too can utilize this image caption feature to display about this important event taken place too in your site.

How to display image caption in WordPress under featured images?

Now, since you already learned about what is image caption and when is it useful, now you may want to display it in your site under the featured image to give the credit to the person who helped you click that image right? Well, then why the wait. So, let’s us move ahead and display image caption under the featured image of your posts.

For the display of the image caption under the featured image, you first have to know that which file is rendering the display of the featured image in your site. Now, after knowing that, you can open up that file and paste the below PHP code under the featured image to display image caption of that image:

<?php if (get_post(get_post_thumbnail_id())->post_excerpt) { // search for if the image has caption added on it ?>
<span class="featured-image-caption">
<?php echo wp_kses_post(get_post(get_post_thumbnail_id())->post_excerpt); // displays the image caption ?>
<?php } ?>

Here, below is the screenshot about the addition of the caption in the uploaded image in your WordPress site:

Here, above you can see that the Caption text is being added for that image. Now, if you have already added that above provided PHP code in your required file, then, you will probably see the output of this something like below:

Now, if you see the same output as the above, then, we can say that you are able to display the image caption under the featured images of the posts. But, you might not notice the same design as in our output since no CSS is being applied to it. Hence, it will display the output as the plain text. So, to add little bit of styling for your site, you can add the below CSS code in your style.css file of the theme:

.featured-image-caption {
font-size: 20px;
text-align: center;
font-style: italic;


Well, if you have followed up the above tutorial properly and is successful on displaying the image caption under the featured image of your posts, then, we can say that you are now able to display image caption under the featured images in your site better than before. But, if you are still confused and want to know more on this, then, drop the comment below in the comment box and we will follow it up.

Post navigation

Bishal Napit

Bishal Napit is a WordPress theme developer from Tansen, Palpa, with a passion to learn more on WordPress.

8 thoughts on “Display Image Caption Under Featured Images In WordPress

  1. Where EXACTLY do you put this php? You can’t open up the image and put anything that’s not part of the picture.

  2. Hi Bishal,
    Thanks for this nice tutorial. I have two more problems.
    First is that I want the caption to appear on the right bottom corner of the featured image and not below the image.
    Secondly the caption does not appear on the featured image thumbnails of the post on home page. My home page is not a static front page. It is displaying my posts and I want the caption to appear on the thumbnails of featured image on home page also.
    Can you please provide a solution to both of my problems?

    1. Firstly, for the first issue, you need to apply custom CSS for same as needed for your site. The above CSS code in this tutorial displays the caption under the featured image aligning it to center. And the CSS code will probably differ on implementation about how it is implemented within the theme.

      And for the second issue, for that, you need to apply the same PHP code as above within the file, which displays the posts loops for your site too, for the blog, archive as well as the search results page.

      So, can you once check on both and manage as needed for your site?

  3. Works great. But some of my posts don’t have a featured image and for those the code seems to display the article excerpt instead. Any way to avoid that?

    1. I did not get any such issue in my development environment. However, you can try modifying the above provided PHP code in the tutorial with the below ones and check for the same:

      <?php if ( has_post_thumbnail() && ( get_post( get_post_thumbnail_id() )->post_excerpt ) ) { ?>
          <span class="featured-image-caption">
              <?php echo wp_kses_post( get_post( get_post_thumbnail_id() )->post_excerpt ); ?>
      <?php } ?>
    1. Can you once try the below CSS code instead in the Additional CSS Box and check once:

      .featured-image-caption {
          text-align: center;
          display: block;

      Hope this works out for you.

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.