Archived topic
Featured Image doesn't show description
3 replies · Started by Kathrin on March 10, 2021
Hi, I have written a description that is linked to the featured image but it isn't shown? What could be the problem?
Greetings Kathrin
Hi there,
Featured images don't display Captions or Descriptions by default.
If you want to add the Description below the single post featured image then add this PHP Snippet to your site:
add_action( 'post_thumbnail_html', 'db_auto_single_featured_description', 10 );
function db_auto_single_featured_description( $html ) {
$get_description = get_post(get_post_thumbnail_id())->post_content;
if ( is_single() && !empty($get_description) ){
$html .= '<div class="wp-caption">'. $get_description . '</div>';
}
return $html;
}
Adding PHP: https://docs.generatepress.com/article/adding-php/
Then a little CSS:
.featured-image .wp-caption {
line-height: 2em;
font-size: 0.8em;
text-align: left;
}
Oh :) Thank you very much! I will try it!
Works great!
Greetings Kathrin
Glad to hear that!