Use the shortcode handler img_caption_shortcode
to render the HTML for you, though you do need to pass it a width (which we can easily get with wp_get_attachement_image_src
:
function wpse_138126_thumbnail_caption( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
if ( $post = get_post( $post_thumbnail_id ) ) {
if ( $size = wp_get_attachment_image_src( $post->ID, $size ) )
$width = $size[1];
else
$width = 0;
$html = img_caption_shortcode(
array(
'caption' => trim( "$post->post_excerpt $post->post_content" ),
'align' => 'alignright',
'width' => $width,
),
$html
);
}
return $html;
}
add_filter( 'post_thumbnail_html', 'wpse_138126_thumbnail_caption', 10, 5 );
Related Posts:
- Multi user site and image captions
- Text editor on WP caption [closed]
- How to remove a empty in wp caption shortcode?
- Add extra class to wp-caption?
- wp_get_attachment_caption to pull Image Caption or alt
- Showing image description along with embedded links below post images
- Captions for More Fields groups, not just individual fields
- How to add line breaks inside Gallery Captions
- Can’t insert caption into image
- Remove wp-caption but still show the image
- Image caption not rendering on some images – Shapely theme
- slider stripping out caption/excerpt line breaks
- How to always add caption element to images – even if empty?
- Get Image Description
- make WordPress image captions responsive
- Featured image shortcode
- Are captions stored anywhere?
- How to wrap WordPress image captions inside H2, H3 tags?
- Remove image caption from post excerpt
- How I can get image description/title/alt for gallery image?
- Is there a way to define a default caption to all uploaded images
- How to add a link in a image’s caption?
- Alter media caption/description conflict in WordPress?
- Multi-line captions on attachments
- How to display a shortcode caption somewhere other than the_content
- Caption in Page adding unwanted 10px to width
- How to limit post content and remove image caption from it
- Nested Shortcode Inside [caption] Doesn’t Process
- Update caption for metabox gallery images
- How to show post format gallery metabox image caption in the post front end
- Get image captions for images on gallery post format metabox
- Get post embedded image caption
- Adjust image caption within visal editor
- Drag images with caption in WP editor
- Different captions for the same image in multiple galleries. Edit Image in Gallery locally
- Adding a video description in a similar way to a image caption
- Include captions
- Remove inline width from figure
- How do themes render caption texts in extended markup (e.g. “wp-caption” paragraphs)
- HTML tags in WordPress image caption
- Add attribute to caption shortcode from custom attachment field
- Automatically add image caption with values from a post parent field?
- PHP code to call image Caption, Alternative Text, and Decription?
- Getting Featured Image Caption to Only Show if Populated
- Caption shortcodes not including caption as attribute
- Add post-thumbnail after first paragraph including the caption
- Gallery IDS and Captions: hide/show on a per ID basis
- Add caption functionality to custom WordPress theme
- echo image caption
- XML-RPC: How to add media caption to uploaded image?
- How to add ‘data-caption’ inside an anchor tag
- How to check if there is image title, caption, description?
- Removing height and width from images with a caption
- Include caption underneath post images
- Turn off image captions in gallery view?
- Move Image Captions Inside Link ( tag) if Added
- Can I nest a element within tags from default wordpress?
- How to add custom classes to figure element only if image has caption?
- modify wordpress caption shortcode
- Replace image caption with its title and description
- Forcing max-width for image captions
- How do I remove featured images and captions from a wordpress RSS feed?
- Way to add captions to gallery images by code
- Omit image captions from get_the_content()
- How to dynamically insert in the image caption?
- Displaying an image’s alt title and caption inside a fancybox window. Working, but showing the same alt and caption for each image
- add_filter img_caption_shortcode not implemented
- How to add a caption to an image attachment in a file list?
- caption shortcode using image alt as caption
- WordPress Caption Formatting
- WP Gallery showing captions twice
- Custom caption output for custom image size
- Random home page background images with caption text
- How to edit caption for images and exclude it from excerption query?
- Style wordpress image captions in RSS
- How to join Caption AND Description Meta Fields as one combined-caption in Image Block
- Not able to remove caption shortcode from the content
- How to modify image caption in posts?
- how automatically show the image title before the image caption/description in a wordpress gallery?
- How to Display Image Caption but Not Alt Text
- How to auto add image caption from image alt?
- Unknow shortcode read on display site
- Is there a way to create referable automatic numbering in image captions?
- How to hide / remove attachment “alt” or “caption” field in Admin?
- Problem to return more than single line captions
- Displaying “alt” attribute text as captions?
- Add caption to thumbnails in content
- How do I change the woocommerce product gallery to show all thumbnails instead of three at a time in a carousel?
- Move captions under gallery images in twenty fourteen theme
- Remove Captions from Custom Gallery function.php
- page displaying media caption shortcodes
- SQL query to remove first image in all posts
- How to change images size after theme modification?
- How to add a credit line to a photo caption
- Move caption in on attachment page
- Wrap a post image with a div if it doesn’t have a caption
- Check if a field is capitalized?
- How to show image caption in Woocommerce gallery
- How to display featured image caption only if exists?
- Adding caption to all images inside an article