Show featured image captions
If you are planning to organize any conference or festival, there are many ways to get help via our forum.
- GK User
- Wed Jan 18, 2017 7:06 pm
The captions for a standard post's featured image do not display, what changes do I need to make so that the captions are displayed please? ( in Event theme )
thanks
thanks
-
- Senior Boarder
- Joshua M
- Thu Jan 19, 2017 9:28 am
Hello,
This feature is not included in Events theme, but try to add the following code into your functions.php file:
and change this line from content-featured.php:
into:
This feature is not included in Events theme, but try to add the following code into your functions.php file:
- Code: Select all
function gk_post_thumbnail_caption($raw = false) {
global $post;
// get the post thumbnail ID
$thumbnail_id = get_post_thumbnail_id($post->ID);
// get the thumbnail description
$thumbnail_img = get_posts(array('p' => $thumbnail_id, 'post_type' => 'attachment'));
// return the thumbnail caption
if ($thumbnail_img && isset($thumbnail_img[0])) {
if($thumbnail_img[0]->post_excerpt != '') {
if($raw) {
return apply_filters('gavern_thumbnail_caption', strip_tags($thumbnail_img[0]->post_excerpt));
} else {
return apply_filters('gavern_thumbnail_caption', '<div class="gk-image-caption">'.$thumbnail_img[0]->post_excerpt.'</div>');
}
}
} else {
return false;
}
}
and change this line from content-featured.php:
- Code: Select all
<?php the_post_thumbnail(); ?>
into:
- Code: Select all
<?php the_post_thumbnail(); ?>
<?php if(is_single() || is_page()) : ?>
<?php echo gk_post_thumbnail_caption(); ?>
<?php endif; ?>
-
- Moderator
- GK User
- Tue Feb 07, 2017 9:57 am
Thanks Joshua, that worked !
-
- Senior Boarder
3 posts
• Page 1 of 1