Archived topic
Image Caption/Description problem
14 replies · Started by Kaleem on July 1, 2018
Hi Sir, when I insert either the caption or description of the featured image, none appears with the image.
I want them appeared beneath the image. Thank you.
Hi there, this topic provides a PHP Snippet for adding the Caption below the featured image:
https://generatepress.com/forums/topic/featured-image-caption/#post-598608
Adding PHP: https://docs.generatepress.com/article/adding-php/
Hi, I added the snippet in child function, and the caption now shows, but it appears at the top of the title instead.
please visit the url
Try this instead:
add_action( 'generate_after_entry_header', 'db_featured_image_caption', 15 );
function db_featured_image_caption() {
$get_description = get_post(get_post_thumbnail_id())->post_excerpt;
if(!empty($get_description)){
echo '<span class="featured_caption">' . $get_description . '</span>';
}
}
Great, it works. But it does not fit with the padding of the image. Is there any suggestion to make the caption follow the same padding of the image? Thanks a lot.
The padding is consistent. The problem is that your featured image isn't wide enough:
http://www.screencast.com/t/aVhsGfF9uap7
Oh ok. Thank you for your help.
No problem :)
@Leo, I just observed that the caption only works on Posts only, not Pages.
Any suggestion to make it display on both post and page? Thanks for your patience.
Try the edited code here: https://generatepress.com/forums/topic/image-caption-description-problem/#post-612878
Wow that's great. Thank you so much. @Leo
Glad I could help :)
This seems to work for me, except for one thing, it's not centered on the photo. It's all the way to the left. How can I center it under the photo
Steve
Try this CSS:
.featured_caption {
text-align; center;
}
Adding CSS: https://docs.generatepress.com/article/adding-css/
Put in simple css and it does not seem to work. I have another entry could that be an issue?
Looks like this:
.page-header-image-single {
text-align: center;
}
.featured_caption {
text-align; center;
}