List the Generated Sizes of Each Image
Adds a box to the image edit screen listing every size WordPress generated for it, with dimensions, file size and a link to open each one, to check crops and spot missing sizes.
Opens WPIDE on
Code
add_action( 'add_meta_boxes_attachment', function ( $post ) {
if ( ! wp_attachment_is_image( $post ) ) {
return;
}
add_meta_box( 'wpide-image-sizes', 'Generated sizes', function ( $post ) {
$meta = wp_get_attachment_metadata( $post->ID );
$sizes = $meta['sizes'] ?? array();
$base = trailingslashit( dirname( (string) wp_get_attachment_url( $post->ID ) ) );
if ( ! $sizes ) {
echo '<p>No extra sizes were generated.</p>';
return;
}
echo '<table class="widefat striped"><thead><tr><th>Size</th><th>Dimensions</th><th>File size</th></tr></thead><tbody>';
foreach ( $sizes as $name => $size ) {
printf(
'<tr><td><a href="%s" target="_blank" rel="noopener">%s</a></td><td>%d × %d</td><td>%s</td></tr>',
esc_url( $base . $size['file'] ),
esc_html( $name ),
(int) $size['width'],
(int) $size['height'],
! empty( $size['filesize'] ) ? esc_html( size_format( $size['filesize'] ) ) : '–'
);
}
echo '</tbody></table>';
$missing = array_diff( array_keys( wp_get_registered_image_subsizes() ), array_keys( $sizes ) );
if ( $missing ) {
echo '<p class="description">Not generated: ' . esc_html( implode( ', ', $missing ) ) . ' (the original may be too small).</p>';
}
}, 'attachment', 'normal', 'low' );
} );
Notes
Sizes registered after the image was uploaded will be missing until you regenerate it.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.