Home / Add Media File Size Column
Duplicate Snippet

Embed Snippet on Your Site

Add Media File Size Column

Display the file size in a separate column in the Media screen

300+
Code Preview
php
<?php
add_filter( 'manage_upload_columns', function ( $columns ) {
	$columns ['file_size'] = esc_html__( 'File size' );
	return $columns;
} );
add_action( 'manage_media_custom_column', function ( $column_name, $media_item ) {
	if ( 'file_size' !== $column_name || ! wp_attachment_is_image( $media_item ) ) {
		return;
	}
	$filesize = size_format( filesize( get_attached_file( $media_item ) ), 2 );
	echo esc_html( $filesize );
}, 10, 2 );

Comments

Add a Comment