Skip to content

Instantly share code, notes, and snippets.

@gmmedia
Created July 27, 2022 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmmedia/a955e969c5974276529c9551f5c27159 to your computer and use it in GitHub Desktop.
Save gmmedia/a955e969c5974276529c9551f5c27159 to your computer and use it in GitHub Desktop.
Add Media Library Column: File Size
<?php
// Add Media Library Column: File Size
// Need help: https://bloggerpilot.com/snippet-media-filesize/
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)) {
return;
}
$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: 10px;}</style>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment