X

How to Add Dimensions Column to WordPress Media Library

Snippets by IsItWP

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.

add media library column with images width and height wp_get_attachment_metadata

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.

Comments   Leave a Reply

  1. Hello,
    Thank you for this snippet. Any chance of making the Dimensions column sortable?
    Thanks again.

  2. This is great, thanks!

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

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

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

  6. 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 Cancel reply

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!