PHP snippet · Media & Files

Media library file size and dimension columns

Adds Dimensions and File size columns to the media library list, so the 4 MB hero image is visible without opening anything.

About this php snippet

The media library list gives you a thumbnail, a name, and a date, but not the two things you actually need when you are hunting for whatever is making a page heavy. Today, finding the 4 MB hero somebody uploaded straight off a camera means opening attachments one at a time.

Two columns, no settings, and the answer is on screen.

What it does

  • Adds a Dimensions column showing the width and height of each image
  • Adds a File size column, formatted so it reads at a glance
  • Sits alongside the existing columns with nothing to configure

Good to know

  • File size is read from the attachment metadata where WordPress recorded it, and falls back to measuring the file on disk for older uploads that predate that field, so the column is not blank on a library that has been going for years
  • Anything without dimensions, such as a PDF or an audio file, shows a dash rather than a broken value
  • These are display columns, not sortable ones. They are for scanning a page of results, not ordering the whole library.
  • This is the list view. The grid view is unchanged.
  • Pairs well with the EMCP image optimization module when you are auditing a library that has got out of hand.

More php snippets