There is nothing WordPress specific here, but you could make your code easier to read by removing the repeating parts.
if ( $id = get_post_thumbnail_id() )
{
$post = get_post( $id );
$data = array(
$post->post_content,
$post->post_excerpt
);
// remove empty elements from array
$data = array_map( 'trim', $data );
$data = array_filter( $data );
// escape the elements
$data = array_map( 'esc_html', $data );
if ( ! empty ( $data ) )
print '<div class="featured_caption">' . join( '<br />', $data ) . '</div>';
}
Related Posts:
- How to get featured image’s width and use elsewhere in template?
- set_post_thumbnail_size vs add_image_size
- How to get all featured image sizes and their URLs?
- Post thumbnail alt title
- Get featured image on Blog Index
- Can I refresh the thumbnails programmatically?
- New image size version only for the Featured Image file
- Prevent WordPress from cropping GIF files
- Getting custom-sized featured image’s URL?
- Retrieve featured image as object
- wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); Getting thumb from wrong loop
- Featured image size in ADMIN panel?
- Featured image with the same height thumbs returns wrong thumb
- Set post thumbnail as background
- How to get_posts having post thumbnail?
- How to get the image sizes, in a function, as per the sizes mentioned in the media settings?
- How to Remove Two (Related) wp_postmeta Rows?
- Set featured image size for a custom post type
- How to change the height of featured image in Twenty Eleven child theme
- how to set featured image as facebook post thumbnail
- How to delete posts that does not have a thumbnail?
- add_image_size not working with the_post_thumbnail
- If no featured image is set, default.png from core is shown
- Photo gallery with Featured Images
- Need clear explanation about medias/files/attchments
- Thumbnail Cropping with add_image_size?
- How to handle and keep image quality of featured image uploads
- post_thumbnail_html only for specific thumb size
- How to automatically resize animated GIFs used as Featured Images, without losing animation?
- Exclude featured image from attachment loop
- How to not show post_thumbnail from specific category for not logged users
- Archive show thumbnail
- Exclude featured image from gallery code stops Lightbox from working
- Post thumbnail not working after regenerate
- How to write conditional for custom checkbox in featured image meta box
- Generate image for newly added size
- Cleaning up bloated wp_postmeta table by removing multiple _thumbnail_id’s?
- How To Add and Display Category Image
- specify size of post preview image (not post thumbnail)
- featured image inside post
- How to deal with wordpress images?
- get_post_thumbnail_id /set_post_thumbnail not working
- Featured image/thumbnail fallback placeholder image
- Add class to custom thumbnail
- How can i hide post without thumbnails/featured images from index pages?
- How to add gallery support in WordPress?
- Wanting to change presentation from full post to featured image (post_thumbnail) only
- get_the_post_thumbnail wordpress 3.5
- How do WP know an image is a post thumbnail
- Featured Image Link to next post?
- How to get a page’s featured image from a term slug (same name)
- Thumbnail is showing outside its div instead of inside it
- How do I get only the image URL from the_post_thumbnail()?
- Add extra fields to the post’s featured image
- WordPress showing image as thumbnail without using thumbnail
- Get post thumbnail to display favorites
- Unrestricted height thumbnails
- WordPress generated thumbnails
- How can I assign bloginfo path or thumbnail path to a variable and call it in markup?
- how to resize thumbnail image
- Get a random thumbnail from posts belonging to a specific taxonomy
- Custom caption output for custom image size
- how to create extra post thumbnail with merge of an icon image?
- Getting featured image setting as background
- WordPress 3.3.1 not cropping featured image
- How can I set a post thumbnail image without making a featured image?
- Upload image through URL?
- First Image not loading on Mobile Version of Website
- the_post_thumbnail doesn’t resize properly
- cropping post thumbnail without falsing them to crop to dimensions
- How to show Thumbnail size, caption, extension in WordPress?
- Get featured image and additional posts thumbnail WordPress REST API
- featured image background
- Image doesn’t show up using get_the_post_thumbnail_url();
- Featured image size always cropped bottom
- Unable to display the post thumbnail in the loop
- How to add post title below the featured image in the plugin code?
- Show a page of non-standard-sized featured images
- wp_get_attachment_image_src() works on index, but not on Archives
- how to use Data URI for images in WP?
- Disable loading Thumbnail On Mobile [closed]
- Featured images not showing up
- MySQL swap one table for another?
- Generate smaller post thumbnail for archives
- Setting featured image based on related post
- Can’t update/save featured image
- Display featured image on blog page
- How to remove featured images from posts
- Wrap Featured Image in a Link
- Plugin scans for images in post_content, how about “featured image”?
- How to add thumbnails to posts?
- How to regenerate image thumb with size that is specified in media section
- Retreive post thumbnail and display it as tooltip on hover?
- How to store all featured images in a different folder?
- Why does Facebook not want to display my post thumbnails?
- Convert thumbnail ID into image URL
- How to display recent posts on home page with title, post date, author and featured image?
- Post thumbnail not displaying in correct position
- Previous/Next Post – Cannot Display Featured Image
- php code for image fetching