I’d love to add a caption to my feature image on blog posts. Do you have an update coming soon that might allow for this?
1 Answers
To resolve this issue, you can add the following code to the functions.php file:
function the_post_thumbnail_caption() {
global $post;
$thumbnail_id = get_post_thumbnail_id($post->ID);
$thumbnail_image = get_posts(array('p' => $thumbnail_id, 'post_type' => 'attachment'));
if ($thumbnail_image && isset($thumbnail_image[0])) {
return '<div class="front-caption">'.$thumbnail_image[0]->post_excerpt.'</div>';
} else {
return;
}
}
Then open the content-sigle.php file, find and replace the following code:
<?php if( has_post_thumbnail() ) : ?>
<div class="entry-thumbnail"><?php the_post_thumbnail(); ?>
With new code:
<?php if( has_post_thumbnail() ) : ?>
<div class="entry-thumbnail"><?php the_post_thumbnail(); ?>
<p class="caption"><?php echo the_post_thumbnail_caption(); ?>
Hope this helps !
Please login or Register to submit your answer