How to display featured image caption only if exists?

I am a “little late” but this solution worked great for me. It will show the div only if the caption is not empty. <?php $get_description = get_post(get_post_thumbnail_id())->post_excerpt; the_post_thumbnail(); if(!empty($get_description)){//If description is not empty show the div echo ‘<div class=”featured_caption”>’ . $get_description . ‘</div>’; } ?>

Delete post media except featured image

If someone has clashed with such problem, I solved it in this way: $attachments = get_posts( array( ‘post_type’ => ‘attachment’, ‘posts_per_page’ => -1, ‘post_status’ => ‘any’, ‘post_parent’ => $post_id ) ); $thumbId = get_post_thumbnail_id($post_id); foreach ( $attachments as $attachment ) { if($thumbId != $attachment->ID) wp_delete_attachment( $attachment->ID, true ); }

How to get the real thumbnail size?

wp_get_attachment_metadata – Retrieve attachment meta field for attachment ID. $image_meta = wp_get_attachment_metadata( $attachment_id, $unfiltered ); As you can see, the width x height is nested in sizes for each size. Array ( [width] => 2400 [height] => 1559 [file] => 2011/12/press_image.jpg [sizes] => Array ( [thumbnail] => Array ( [file] => press_image-150×150.jpg [width] => 150 … Read more