Archived topic
Featured Image Caption Remove from WP ShowPost
3 replies · Started by Hermann on November 14, 2021
Hello,
I am hoping to get some help. I added the PHP code below to show the caption on the featured image in posts only. The issue I am running into is that in the post page I have a section under the article called "Recommended Stories" which shows the featured image thumbnail, category, title.
My question is how I can remove the featured image caption from the Recommended Stories section of the post, and only have the featured image caption show on the featured image of the article.
Here is post that shows the issue https://www.delazing.com/2021/10/05/king-ming-chang-leisure-farm/
add_filter( 'post_thumbnail_html', 'custom_add_post_thumbnail_caption',10,5 );
function custom_add_post_thumbnail_caption($html, $post_id, $post_thumbnail_id, $size, $attr) {
if( $html == '' || ! is_single() ) {
return $html;
} else {
$out = '';
$thumbnail_image = get_posts(array('p' => $post_thumbnail_id, 'post_type' => 'attachment'));
if ($thumbnail_image && isset($thumbnail_image[0])) {
$image = wp_get_attachment_image_src($post_thumbnail_id, $size);
if($thumbnail_image[0]->post_excerpt)
$out .= '
$out .= $html;
if($thumbnail_image[0]->post_excerpt)
$out .= '<p class="wp-caption-text thumb-caption-text">'.$thumbnail_image[0]->post_excerpt.'</p>
';
}
return $out;
}
}
Hi there,
Try this CSS:
.wp-show-posts .wp-caption-text {
display: none;
}
Adding CSS: https://docs.generatepress.com/article/adding-css/
Hi Leo,
That did the trick.
As always awesome support.
Thank you.
No problem :)