Created
July 27, 2022 12:28
-
-
Save gmmedia/a955e969c5974276529c9551f5c27159 to your computer and use it in GitHub Desktop.
Add Media Library Column: File Size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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