Home / admin / Add media library column with image width and height
  • How to Add media library column with image width and height


    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 ) ( click code to copy )

    wordpress snippet : PHP

    function wh_column( $cols ) {
    	$cols["dimensions"] = "Dimensions (w, h)";
    	return $cols;
    function wh_value( $column_name, $id ) {
        $meta = wp_get_attachment_metadata($id);
               echo $meta['width'].' x '.$meta['height'];
    add_filter( 'manage_media_columns', 'wh_column' );
    add_action( 'manage_media_custom_column', 'wh_value', 10, 2 );

    ( WordPress codex functions, hooks, in this snippet. )

    wp_get_attachment_metadata, add_filter, add_action, _n, wp,
  • 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.


    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?

      • MatthewJ

        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.

  • Andrea Bersi

    I suggest this code
    function wh_value( $column_name, $id ) {
        if ( $column_name == “dimensions” ):
        $meta = wp_get_attachment_metadata($id);
               echo $meta[‘width’].’ x ‘.$meta[‘height’];

    because if you have anothre column this code non rewrire the dimensions

    • Boris

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

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