Show each file's size and image dimensions in the Media Library list view, so you can spot oversized uploads at a glance.
add_filter( 'manage_media_columns', function ( array $columns ): array {
$columns['nahnu_filesize'] = 'File size';
$columns['nahnu_dimensions'] = 'Dimensions';
return $columns;
} );
add_action( 'manage_media_custom_column', function ( string $column, int $post_id ): void {
$meta = wp_get_attachment_metadata( $post_id );
if ( 'nahnu_filesize' === $column ) {
$bytes = $meta['filesize'] ?? 0;
if ( ! $bytes ) {
$file = get_attached_file( $post_id );
$bytes = $file && file_exists( $file ) ? filesize( $file ) : 0;
}
$size = $bytes ? size_format( $bytes, 1 ) : '—';
echo $bytes > MB_IN_BYTES ? '<strong style="color:#b32d2e">' . esc_html( $size ) . '</strong>' : esc_html( $size );
}
if ( 'nahnu_dimensions' === $column ) {
echo isset( $meta['width'], $meta['height'] ) ? esc_html( $meta['width'] . ' × ' . $meta['height'] ) : '—';
}
}, 10, 2 );
Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.
The Media Library doesn’t show file sizes in its list, so a 12 MB photo looks the same as a 60 KB one. This snippet adds two columns and highlights anything over 1 MB.
manage_media_columns adds the columns and manage_media_custom_column fills them for each file. Since WordPress 6.0 the file size is stored in the attachment metadata. For older uploads the snippet reads it from the file on disk.
Image width and height also come from the metadata. Files over 1 MB are shown in bold red.
Go to Media → Library and switch to list view. You should see File size and Dimensions columns.