How to Display Caption on Featured Image in Genesis

How to Display Caption on Featured Image in Genesis

Much like any WordPress themes, Genesis themes allow users to display a caption under their images when they are use in side the article. However, if you want to display a caption on a featured image, you need to use custom code snippet inside your theme functions.

A caption on a featured image can be useful for reasons — display copyright info, mention the source of your image, add meaning to your featured image for storytelling etc. The point being displaying caption in featured image should be a default feature in WordPress themes (and Genesis Themes) considering its importance and use cases.

Working on a recent project and hunting for this solution led me to Genesis Facebook Group, and invariably, Sridhar came to my rescue. Indeed, the man has a HUGE heart. πŸ™‚

If you want to learn how to use a caption on featured image in Genesis, follow along.

Step #1: Display Featured Image with Caption in Genesis (add code to functions.php)

https://gist.github.com/topleague/70b95c86b5ae64f4f34ebc362f6129d4

Step #2: Style Featured Image Caption in Genesis (add code to style.css)

https://gist.github.com/topleague/da808f0a0829880c259b5e9bed1fc9dd

Step #3: Enable Font Awesome on your theme (optional – required in the above css code)

https://gist.github.com/topleague/cfa71815943b603a117192404abf230b

That’s it – go creative and add a meaningful caption to your featured image.

Please, let me know if you have any questions.


Comments

3 responses to “How to Display Caption on Featured Image in Genesis”

  1. A tad late, but what would be the code to add ONLY the caption to an existing featured image?

    1. Unable to understand your question. Can you be a bit more elaborative!

    2. Try this:


      /* Code to Display Featured Image on top of the post */
      add_action( 'genesis_before_entry', 'featured_post_image', 8 );
      function featured_post_image() {
      if ( ! is_singular( 'post' ) ) return;

      $image = genesis_get_image( 'format=url&size=post-image' ); // get the URL of featured image.

      $thumb_id = get_post_thumbnail_id( get_the_ID() ); // get the alt text of featured image.
      $alt = get_post_meta( $thumb_id, '_wp_attachment_image_alt', true );

      $caption = get_post( $thumb_id )->post_excerpt; // get the caption of featured image.
      $caption_html = $caption ? ''. $caption . '' : ''; // Construct the caption HTML if caption is present for the featured image..

      printf( '%s', esc_url( $image ), $alt, $caption_html ); // display the featured image with caption (if present) beneath the image.

      }

      </codes