EDIT. I got this working, see my own answer below:
Now, if someone has any clue as to how I can get this sortable, please chime in! 🙂
—————- Original question —————-
How can I add a custom column to the attachment post type? I’m finding ways to add them to posts, pages or custom post types. But for native post types like attachments, how?
I would like to display the attachment file size in it’s own column.
Working code:
// Add custom column with file size info to attachment page
add_filter( 'manage_media_columns', 'bb2_manage_media_columns', 10, 2 );
function bb2_manage_media_columns( $columns )
{
$columns['filesize'] = __( 'Storlek', 'bb2' );
return $columns;
}
add_action( 'manage_media_custom_column', 'bb2_manage_media_custom_column', 10, 2 );
function bb2_manage_media_custom_column( $column_name, $id )
{
switch ( $column_name )
{
case 'filesize' :
$bytes = filesize(get_attached_file($id));
echo size_format($bytes);
break;
default :
break;
}
}