Skip to content

trepmal.com

  • Home
  • Plugins
  • Github
  • Me on WP.org
  • Donate

Categories

  • WordPress Bits (149)
  • Uncategorized (11)
  • Scripts (5)
  • Tidbits (5)
  • Fun (3)

Tags

  • wordpress (30)
  • administration (16)
  • plugin (9)
  • free download (8)
  • functions.php (8)

Year

  • 2018 (8)
  • 2016 (2)
  • 2015 (4)
  • 2014 (19)
  • 2013 (11)

Function: wp_get_attachment_metadata

Add Dimensions Column to Media Library Page

If you need quick access to the image dimensions from the Media Library, this will add a ‘Dimensions’ column

add_filter( 'manage_media_columns', 'add_media_columns');
function add_media_columns( $columns ) {
    $columns['dimensions'] = 'Dimensions';
    return $columns;
}
add_action( 'manage_media_custom_column', 'fill_media_columns', 10, 2 );
function fill_media_columns( $column_name, $id ) {
    switch ( $column_name ) {
        case 'dimensions' :
            $meta = wp_get_attachment_metadata( $id );
            if ( isset( $meta['width'] ) ) {
                echo $meta['width'].' x '.$meta['height'];
            }
        break;
    }
}

Don’t forget to prefix these to avoid clashes with other code!

Posted on March 11, 2011April 25, 2014Categories WordPress BitsLeave a comment on Add Dimensions Column to Media Library Page
Proudly powered by WordPress