Hi! This is not built inside the Editor today. I don’t see a straightforward way to do that, but I see this plugin works perfectly: https://ww.wp.xz.cn/plugins/featured-image-caption/
I understand your preference is a snippet, I was able to find this in forums but was unable to test this;
- Locate the
functions.php file of your active child theme (or create a child theme if you’re using the main TT4 theme to prevent updates from overwriting your changes).
- Add the following code:
function add_featured_image_caption() {
if (is_single() && has_post_thumbnail()) {
global $post;
$thumbnail_id = get_post_thumbnail_id($post->ID);
$caption = wp_get_attachment_caption($thumbnail_id);
if ($caption) {
echo '<div class="featured-image-caption">' . esc_html($caption) . '</div>';
}
}
}
add_action('wp_after_header', 'add_featured_image_caption');
- Style the caption if needed by adding CSS to your customizer or child theme’s
style.css file:
.featured-image-caption {
font-style: italic;
text-align: center;
margin-top: 5px;
color: #666;
}
This code snippet checks if the current post is a single post with a featured image, retrieves the caption, and displays it right below the image if a caption exists.
-
This reply was modified 1 year, 6 months ago by
Mary Hubbard.
-
This reply was modified 1 year, 6 months ago by
Mary Hubbard.
Hi @4thhubbard
Thank you so much for your effort. I just ran a test on snippet above and it appears no caption is showing. I believe this is legacy or maybe because I am using cover block in my template to show the featured image.
Feedback for developers:
Image block can display Caption. Image block can not show featured image. Hence, it is not usable in templates to show featured together with a caption of credits.
Featured image block does exactly that. It cannot show caption, hence, in templates the featured image is not credited. At times that is a requirement to be allowed to use a given frame.
Cover block no caption either. How about one size fits all? for usability in templates.
Plugin:
Comes across as somewhat legacy oriented. I might give it a try, but I am reaching plus 70 plugins, so I am making all efforts to rewind that
Thx
@hebhansen
Featured image block does exactly that. It cannot show caption, hence, in templates the featured image is not credited. At times that is a requirement to be allowed to use a given frame.
Cover block no caption either. How about one size fits all? for usability in templates.
Thank you so much for this excellent feedback. I personally love these ideas, and I think it would be incredibly beneficial to point this towards our developers so that they can consider including these features in WordPress. If you have the time, may I gently ask you to propose a feature request on this to the Gutenberg team? It would be incredibly beneficial! And your request might even pave the way to bringing this feature into Core WordPress even.
I hope the issue stands resolved. All the best!