Add File Size Column to Media Library
Displays the file size of each attachment in a new column on the Media Library list view.
PHPby SnipCraft
php
<?php
if ( ! function_exists( 'scseed_add_filesize_column' ) ) {
function scseed_add_filesize_column( $columns ) {
$columns['scseed_filesize'] = __( 'File Size', 'scseed' );
return $columns;
}
}
if ( ! function_exists( 'scseed_show_filesize_column' ) ) {
function scseed_show_filesize_column( $column, $post_id ) {
if ( 'scseed_filesize' !== $column ) {
return;
}
$file = get_attached_file( $post_id );
if ( $file && file_exists( $file ) ) {
echo esc_html( size_format( filesize( $file ) ) );
} else {
echo '—';
}
}
}
add_filter( 'manage_media_columns', 'scseed_add_filesize_column' );
add_action( 'manage_media_custom_column', 'scseed_show_filesize_column', 10, 2 );#admin#columns#file-size#media