Do you want to add a Dimensions column to WordPress media library? Dimensions column can help users understand the width and height of their images.
Instructions:
All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:
function wh_column( $cols ) { $cols["dimensions"] = "Dimensions (w, h)"; return $cols; } function wh_value( $column_name, $id ) { $meta = wp_get_attachment_metadata($id); if(isset($meta['width'])) echo $meta['width'].' x '.$meta['height']; } add_filter( 'manage_media_columns', 'wh_column' ); add_action( 'manage_media_custom_column', 'wh_value', 10, 2 );
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: 62 best free WordPress blog themes or 7 best WordPress contact form plugins.
Addition to display filesize as well
function dimension_value( $column_name, $id ) {
$meta = wp_get_attachment_metadata($id);
if(isset($meta[‘width’]))
echo $meta[‘width’].’ x ‘.$meta[‘height’].”;
$media_filesize = filesize(get_attached_file($id));
$media_filesize = size_format($media_filesize, 2);
echo $media_filesize;
}
which has the advantage of displaying filesize for pdfs etc. (media without width)
Hello,
Thank you for this snippet. Any chance of making the Dimensions column sortable?
Thanks again.
This is great, thanks!
Practical post ! I am thankful for the info ! Does anyone know where I could possibly obtain a blank OR Form 8.010.5 document to work with ?
How can I go about adding dimensions to the “Media Library” tab in the Media Uploader?
I suggest this code
function wh_value( $column_name, $id ) {
   if ( $column_name == “dimensions” ):
   $meta = wp_get_attachment_metadata($id);
          if(isset($meta[‘width’]))
          echo $meta[‘width’].’ x ‘.$meta[‘height’];
   endif;
}
because if you have anothre column this code non rewrire the dimensions
Brilliant, now I can combine it with the show ID snippet! Thank youu Andrea!
Hi! Again, great snippet. Your website is a gold mine for a humble blogger like me 🙂
Â
I just added this code to my functions.php, the Dimensions (w, h) column appears, it works great. But if I look at the column next to it: ‘ID’ now I get the dimensions + ID number.
Example:
Dimensions (w, h) shows 400 x 300
ID column shows 400 x 300 (nospace) 235 (which is the ID number) + one mysterious number between 1 and 5.
Is it normal or is it just me? 🙂
Thanks a lot!
should not display that, what version of wordpress are you running?
Hi Kevin, I’m using WP 3.0.4 and I have yet to upgrade, I know, I’m late 🙂
Ill test things out in that version make sure it has no issues.