Tagged: media library
-
AuthorPosts
-
December 20, 2018 at 3:50 pm #1047764
Hi
Could you suggest how to add File Size column in the WordPress Media Library ?I am trying to track down some large images reported by Google PageSpeed and can’t find them. It would be easier to sort the media library by size and eliminate or swap the main offenders.
Is there a plugin you recommend? It would need to also show which page the image is used.
Many thanks
Tia
December 20, 2018 at 5:07 pm #1047806Hey Tia,
Here is an article for you
If you need further assistance please let us know.
Best regards,
VictoriaDecember 20, 2018 at 5:29 pm #1047818Hi Victoria
I had already found the link you suggested https://premium.wpmudev.org/blog/wordpress-media-library-hidden-features/
It shows a file size column in a screenshot of the media library but it doesn’t say how to make this happen.
I have found suggestions that require editing the functions php file but I would rater not.It seems to easy – I must have missed something??
Thanks
TiaDecember 20, 2018 at 7:32 pm #1047895Hi Tia,
Editing functions php is the way to do it. Have you tried the code you found? This is not really theme related, but you can share the code with us. We’ll have a look for you.
Best regards,
VictoriaDecember 21, 2018 at 1:04 pm #1048163Hi Victoria
According to this article https://sridharkatakam.com/add-file-size-admin-column-wordpress-media-library/
I should be adding the following code to the child theme php but I’m not sure how to do this.add_filter( ‘manage_media_columns’, ‘sk_media_columns_filesize’ );
/**
* Filter the Media list table columns to add a File Size column.
*
* @param array $posts_columns Existing array of columns displayed in the Media list table.
* @return array Amended array of columns to be displayed in the Media list table.
*/
function sk_media_columns_filesize( $posts_columns ) {
$posts_columns[‘filesize’] = __( ‘File Size’, ‘my-theme-text-domain’ );return $posts_columns;
}add_action( ‘manage_media_custom_column’, ‘sk_media_custom_column_filesize’, 10, 2 );
/**
* Display File Size custom column in the Media list table.
*
* @param string $column_name Name of the custom column.
* @param int $post_id Current Attachment ID.
*/
function sk_media_custom_column_filesize( $column_name, $post_id ) {
if ( ‘filesize’ !== $column_name ) {
return;
}$bytes = filesize( get_attached_file( $post_id ) );
echo size_format( $bytes, 2 );
}add_action( ‘admin_print_styles-upload.php’, ‘sk_filesize_column_filesize’ );
/**
* Adjust File Size column on Media Library page in WP admin
*/
function sk_filesize_column_filesize() {
echo
‘<style>
.fixed .column-filesize {
width: 10%;
}
</style>’;
}December 22, 2018 at 9:22 pm #1048655Hi Tia,
Can you give us temporary admin access to your website in the private content box below, so that we can have a closer look?
Best regards,
VictoriaDecember 22, 2018 at 9:34 pm #1048665Hi Victoria
Thanks
Tia- This reply was modified 5 years, 11 months ago by Mike. Reason: moved password to Private Content area
December 23, 2018 at 6:24 pm #1048846Hi,
I tested the function above to add the file size column to the media library, and it worked well on my localhost.
I tried to login to your site to add the function, but I couldn’t, please check the login and the site url.Best regards,
Mike -
AuthorPosts
- You must be logged in to reply to this topic.