Add Image Dimensions to Media Library Tab on Media Upoader

IMHO, I think there’s no much of a solution in the WordPress filters realm…

I managed to make it work using jQuery. Maybe there’s a cleaner way to write this, but it is functional as it is now. Tested in WP 3.1 through 3.4-alpha4

/* 
 * Display Image Dimensions on Media Uploader tabs (Gallery and Library) 
 * Added CSS to adjust the header of the Gallery tab (Order and Actions are pushed to the far right)
 * @author: brasofilo
 */

add_action('admin_head', 'wpse50904_script_enqueuer');

function wpse50904_script_enqueuer() {
    global $current_screen;
    if($current_screen->id == 'media-upload' && ($_GET['tab'] == 'gallery' || $_GET['tab'] == 'library')) {
        echo <<<HTML
            <style>#media-upload th.order-head {width: 5%} #media-upload th.actions-head {width: 10%}</style>
            <script type="text/javascript">
            jQuery(document).ready( function($) {
                $('.filename.new').each(function(i,e){
                    var filename = $(this).next('.slidetoggle').find('thead').find('span[id^="media-dims-"]').clone().appendTo(this);
                    filename.css('float','right').css('margin-right','100px');
                }); 
            });
            </script>
HTML;
    }
}

Leave a Comment