X

Add media library column with image width and height

Advanced Custom Fields Review - default

Adding this snippet to the functions.php of your wordpress theme will add a new column to the media library that will display the images width and height.


( example screenshot )

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 );

Comments  Leave a Reply

  1. yengconstance July 8, 2016 at 11:12 pm

    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 ?

  2. How can I go about adding dimensions to the “Media Library” tab in the Media Uploader?

  3. 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

    1. Brilliant, now I can combine it with the show ID snippet! Thank youu Andrea!

  4. 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!

    1. should not display that, what version of wordpress are you running?

      1. Hi Kevin, I’m using WP 3.0.4 and I have yet to upgrade, I know, I’m late 🙂

        1. Ill test things out in that version make sure it has no issues.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!