updated   : April 22, 2013
we now have 608 snippets

Add media library column with image width and height

wordpress snippet

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 )
snippet :  PHPcopy
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 );
  • MatthewJ

    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!

    • http://wpsnipp.com Kevin Chard

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

      • MatthewJ

        Hi Kevin, I’m using WP 3.0.4 and I have yet to upgrade, I know, I’m late :)

        • http://wpsnipp.com Kevin Chard

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

  • Andrea Bersi

    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

  • http://funwithtp.com tpflanz

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