File size column in the media library
Shows each file’s size in the media library’s list view, so you can spot the heavy ones.
<?php
add_filter(
'manage_media_columns',
static function ( $columns ) {
$columns['snipfire_size'] = __( 'File size' );
return $columns;
}
);
add_action(
'manage_media_custom_column',
static function ( $column, $post_id ) {
if ( 'snipfire_size' !== $column ) {
return;
}
$meta = wp_get_attachment_metadata( $post_id );
$size = is_array( $meta ) && ! empty( $meta['filesize'] ) ? (int) $meta['filesize'] : 0;
if ( ! $size ) {
$file = get_attached_file( $post_id );
$size = $file && file_exists( $file ) ? (int) filesize( $file ) : 0;
}
echo $size ? esc_html( size_format( $size, 1 ) ) : '—';
},
10,
2
);
In these packs
- Images and media: Sharper, lighter images, tidier uploads and a more useful media library.