Output Filter for File Size of Attached Media

Output Filter for returning the File Size by providing the ID of the Media File

If you’re looking for a readable size of the file attached from a list of downloadable files, you can loop through the files in an [each files][/each]  block and return the file size by passing the {@id}  of the file through an Output Filter, like the one below. Usage is: {@ID,return_file_size}  :

function return_file_size($id) {
    $attachment_filesize = size_format(filesize(get_attached_file($id)), 2);
    return $attachment_filesize;
}

As always, these types of functions should be in your functions.php of your theme or in your own plugin.

Submitted through our Slack Chat.

Questions