Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

File size column in the media library

Shows each file’s size in the media library’s list view, so you can spot the heavy ones.

  • Type PHP
  • Runs Everywhere (runs as WordPress loads)
  • Category Media
  • Tested with WordPress 7.1
PHP
<?php

add_filter(
	'manage_media_columns',
	static function ( $columns ) {
		$columns['snipfire_size'] = __( 'File size' );
		return $columns;
	}
);
add_action(
	'manage_media_custom_column',
	static function ( $column, $post_id ) {
		if ( 'snipfire_size' !== $column ) {
			return;
		}
		$meta = wp_get_attachment_metadata( $post_id );
		$size = is_array( $meta ) && ! empty( $meta['filesize'] ) ? (int) $meta['filesize'] : 0;
		if ( ! $size ) {
			$file = get_attached_file( $post_id );
			$size = $file && file_exists( $file ) ? (int) filesize( $file ) : 0;
		}
		echo $size ? esc_html( size_format( $size, 1 ) ) : '—';
	},
	10,
	2
);

In these packs

  • Images and media: Sharper, lighter images, tidier uploads and a more useful media library.

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.