How can I add another column for the file size in the media library?

It is certainly not an everyday question, but an additional column in the media library for the file size in the list view can be a great help to find files that are too large so that they can be optimized afterwards.

add_filter('manage_upload_columns', 'bp_add_column_file_size');
add_action('manage_media_custom_column', 'bp_column_file_size', 10, 2);
add_action('admin_head', 'bp_add_media_styles');

// Create the column
function bp_add_column_file_size($columns)
  $columns['bpFilesize'] = __('File Size');
  return $columns;
// Display the file size
function bp_column_file_size($column_name, $media_item)
  if ('bpFilesize' != $column_name || !wp_attachment_is_image($media_item)) {
  $bpFilesize = filesize(get_attached_file($media_item));
  $bpFilesize = size_format($bpFilesize, 2);
  echo $bpFilesize;
// Format the column width with CSS
function bp_add_media_styles()
  echo '<style>.column-bpFilesize {width: 60px;}</style>';


Without cookies
This website does not use cookies or tracking. More information can be found in the privacy policy.