Managing images and media files becomes easier when you can see their dimensions and file sizes directly in the WordPress Media Library.
This snippet adds two columns to the Media Library’s list view:
- Image Dimensions: Displays the width and height of uploaded images.
- File Size: Displays the size of each uploaded media file in a human-readable format.
This helps developers and content managers identify large images and review media specifications without opening individual attachment details.
How to use
- Add the code to your child theme’s
functions.phpfile or a PHP snippets plugin. - Navigate to WordPress Admin → Media → Library.
- Switch to List View if you’re currently using Grid View.
- Look for the new Image Dimensions and File Size columns.
Example output
| Media file | Image Dimensions | File Size |
|---|---|---|
| homepage-banner.jpg | 1920 × 1080 px | 245 KB |
| company-logo.png | 500 × 500 px | 85 KB |
| product-photo.webp | 1200 × 1200 px | 156 KB |
| brochure.pdf | — | 2.45 MB |
Example data only.
Notes
- Works with the standard WordPress Media Library list view.
- Displays dimensions for image attachments only.
- Displays file sizes for supported media attachments.
- Uses attachment metadata before checking the local file.
- Displays a dash when information is unavailable.
- Does not modify uploaded files or attachment metadata.
- Uses the WordPress
size_format()function for readable file sizes.
/**
* Add image dimensions and file size columns to Media Library.
*/
add_filter(
'manage_media_columns',
'alkesh_add_media_details_columns'
);
function alkesh_add_media_details_columns( $columns ) {
$columns['alkesh_dimensions'] = __( 'Image Dimensions', 'alkesh' );
$columns['alkesh_file_size'] = __( 'File Size', 'alkesh' );
return $columns;
}
/**
* Display image dimensions and file size.
*/
add_action(
'manage_media_custom_column',
'alkesh_display_media_details_columns',
10,
2
);
function alkesh_display_media_details_columns( $column_name, $attachment_id ) {
if ( ! in_array(
$column_name,
array( 'alkesh_dimensions', 'alkesh_file_size' ),
true
) ) {
return;
}
$metadata = wp_get_attachment_metadata( $attachment_id );
// Display image dimensions.
if ( 'alkesh_dimensions' === $column_name ) {
if (
wp_attachment_is_image( $attachment_id ) &&
! empty( $metadata['width'] ) &&
! empty( $metadata['height'] )
) {
printf(
'%1$s × %2$s px',
esc_html( number_format_i18n( $metadata['width'] ) ),
esc_html( number_format_i18n( $metadata['height'] ) )
);
} else {
echo '—';
}
return;
}
// Retrieve file size from attachment metadata.
$file_size = isset( $metadata['filesize'] )
? absint( $metadata['filesize'] )
: 0;
// Fall back to the actual file size when metadata is unavailable.
if ( ! $file_size ) {
$file_path = get_attached_file( $attachment_id );
if ( $file_path && is_file( $file_path ) ) {
$file_size = filesize( $file_path );
}
}
if ( false === $file_size || ! $file_size ) {
echo '—';
return;
}
echo esc_html( size_format( $file_size, 2 ) );
}
Tested on
WordPress 7.1.5
WordPress Admin
Reported by the author on November 25, 2026. WPFolks has not verified this.
