Tagged: 

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #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

    #1047806

    Hey Tia,

    Here is an article for you

    If you need further assistance please let us know.
    Best regards,
    Victoria

    #1047818

    Hi 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
    Tia

    #1047895

    Hi 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,
    Victoria

    #1048163

    Hi 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>’;
    }

    #1048655

    Hi 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,
    Victoria

    #1048665

    Hi Victoria

    Thanks
    Tia

    • This reply was modified 6 years ago by Mike. Reason: moved password to Private Content area
    #1048846

    Hi,
    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

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.