I would like to show the caption for my feature image. I tried to add some code to the functions file of my child theme that you have in one of the posts here but it broke my site.
Also - Thank you. Sorry for my bad manners. End of a long day 
I would like to show the caption for my feature image. I tried to add some code to the functions file of my child theme that you have in one of the posts here but it broke my site.
Also - Thank you. Sorry for my bad manners. End of a long day 
Hi @GeorgiaG,
Please make sure that you copy the entire code. Incomplete code might introduce syntax error that will broke your site. Try this:
if ( ! function_exists( 'x_featured_image' ) ) :
function x_featured_image( $cropped = '' ) {
$stack = x_get_stack();
$fullwidth = ( in_array( 'x-full-width-active', get_body_class() ) ) ? true : false;
if ( has_post_thumbnail() ) {
if ( $cropped == 'cropped' ) {
if ( $fullwidth ) {
$thumb = get_the_post_thumbnail( NULL, 'entry-cropped-fullwidth', NULL );
} else {
$thumb = get_the_post_thumbnail( NULL, 'entry-cropped', NULL );
}
} else {
if ( $fullwidth ) {
$thumb = get_the_post_thumbnail( NULL, 'entry-fullwidth', NULL );
} else {
$thumb = get_the_post_thumbnail( NULL, 'entry', NULL );
}
}
switch ( is_singular() ) {
case true:
printf( '<div class="entry-thumb">%s</div>', $thumb );
printf( '<div class="entry-caption">%s</div>', get_the_post_thumbnail_caption() );
break;
case false:
printf( '<a href="%1$s" class="entry-thumb" title="%2$s">%3$s</a>',
esc_url( get_permalink() ),
esc_attr( sprintf( __( 'Permalink to: "%s"', '__x__' ), the_title_attribute( 'echo=0' ) ) ),
$thumb
);
break;
}
}
}
endif;
That will add caption on you single post feature image. You might need to add the following too.
.entry-caption {
display:block;
padding:10px;
background-color:#fff;
}
Please adjust the value as needed. Further customization from here would be getting into custom development that is outside the scope of our support. Thank you for understanding.
Brilliant. Thank you so much. For my own education was this meant to do the same thing? This was working and then it stopped and the only thing I can find is the following. Should I remove it?
// if (has_post_thumbnail()) {
// display the featured image
the_post_thumbnail();
} else {
// set the featured image
$attachments = get_posts(array(
‘post_type’ => ‘attachment’,
‘post_mime_type’=>‘image’,
‘posts_per_page’ => 0,
‘post_parent’ => $post->ID,
‘order’=>‘ASC’
));
if ($attachments) {
foreach ($attachments as $attachment) {
set_post_thumbnail($post->ID, $attachment->ID);
break;
}
// display the featured image
the_post_thumbnail();
}
} //
Hey @GeorgiaG,
The code you shared is for setting and displaying the featured image rather than showing a caption for the featured image so if you believe you added this code for the caption then you can remove it.
Hope this helps!
Thank you. I did not do the original development so I am just trying to make sense of it. That is very helpful! Best.
You are most welcome!
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.