WordPress media library : display image size

I found with great disapointment that my new mac book does not always display image sizes in finder, little goodie that windows does perfectly. Well I don't exactly like the mac/ pc debate and turned to wordpress media library with a little code snippet that displays  a new column with image dimensions, found on the great stackexchange. Good candidate for basic wordpress extension.

add_filter('manage_upload_columns', 'size_column_register');

function size_column_register($columns) {

    $columns['dimensions'] = 'Dimensions';

    return $columns;
}

add_action('manage_media_custom_column', 'size_column_display', 10, 2);

function size_column_display($column_name, $post_id) {

    if( 'dimensions' != $column_name || !wp_attachment_is_image($post_id))
        return;

    list($url, $width, $height) = wp_get_attachment_image_src($post_id, 'full');

    echo esc_html("{$width}×{$height}");
}

 

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *