Show image dimensions in media library without plugin
My previous article was about how to add image alt automatically without any plugin. In this article, I will show you how to show image dimensions in media library without any plugin. Please note that image dimensions column will show in List mode and not with Grid mode.
Why you should add image size column to media library
I have been working on WordPress websites for the last 5 years, and I know that it is a hassle to switch between your web browser and Photoshop to check image dimensions whenever you are working on a project. Since WordPress doesn’t display the image dimensions by default, it’s a challenge to figure out if the images you have uploaded are of the right size or not.
I have gone through this pain many times, and I found that there is no easy method available to show the image dimensions in media library in WordPress. In this tutorial, I will show you how you can add a column for displaying image dimensions in the media library without using any plugin.
Steps to show image dimensions in media library without plugin
Our recommendations before editing functions.php
Take a full backup of your website or blog.
Be careful before editing the functions.php file. If you don’t want to edit functions.php directly, use the code snippet plugin.
We recommend you use a child theme before any customization on your website. You can use a plugin to create child theme.
Also Check:
Automatically add WordPress image alt text without plugin
Restore WordPress Classic Widget Editor
Change WordPress Login Logo without Plugin
1). Login to wordpress admin Dashboard. Go to ‘Appearance’ then ‘Theme File Editor’. Select currently active theme (If already not selected).
2). Click on ‘Theme Functions’. It is basically the functions.php file of your WordPress website.
3). Add the below code to ‘Theme Functions’ or functions.php and then click on ‘Update File’.
// Show image dimensions column in media library
function wpamit_wh_column( $cols ) {
$cols["dimensions"] = "Dimensions (WxH)";
return $cols;
}
add_filter( 'manage_media_columns', 'wpamit_wh_column' );
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;
}
add_action( 'manage_media_custom_column', 'wh_value', 11, 3 );
I hope this article helped you to show the image dimensions column WordPress library. If you have any queries or need any help please comment below.