The manage_media_columns WordPress PHP Filter allows you to modify the columns displayed in the Media list table.
Usage
add_filter('manage_media_columns', 'my_custom_media_columns', 10, 2); function my_custom_media_columns($posts_columns, $detached) { // your custom code here return $posts_columns; }
Parameters
$posts_columns
(string[]): An array of columns displayed in the Media list table.$detached
(bool): Whether the list table contains media not attached to any posts. Default true.
More information
See WordPress Developer Resources: manage_media_columns
Examples
Add a custom column
Add a new custom column named “File Type” to the Media list table.
add_filter('manage_media_columns', 'add_file_type_column', 10, 2); function add_file_type_column($posts_columns, $detached) { $posts_columns['file_type'] = __('File Type', 'textdomain'); return $posts_columns; }
Remove a column
Remove the “Author” column from the Media list table.
add_filter('manage_media_columns', 'remove_author_column', 10, 2); function remove_author_column($posts_columns, $detached) { unset($posts_columns['author']); return $posts_columns; }
Rearrange columns
Rearrange columns in the Media list table by changing their order.
add_filter('manage_media_columns', 'rearrange_media_columns', 10, 2); function rearrange_media_columns($posts_columns, $detached) { $new_columns = array( 'cb' => $posts_columns['cb'], 'icon' => $posts_columns['icon'], 'media' => $posts_columns['media'], 'date' => $posts_columns['date'], 'author' => $posts_columns['author'] ); return $new_columns; }
Display custom data in a column
Display custom data in a newly added “File Type” column.
add_filter('manage_media_columns', 'add_file_type_column', 10, 2); function add_file_type_column($posts_columns, $detached) { $posts_columns['file_type'] = __('File Type', 'textdomain'); return $posts_columns; } add_action('manage_media_custom_column', 'display_file_type_data', 10, 2); function display_file_type_data($column_name, $post_id) { if ('file_type' == $column_name) { $file_type = get_post_mime_type($post_id); echo $file_type; } }
Add a sortable column
Add a custom sortable column named “File Size” to the Media list table.
add_filter('manage_media_columns', 'add_file_size_column', 10, 2); function add_file_size_column($posts_columns, $detached) { $posts_columns['file_size'] = __('File Size', 'textdomain'); return $posts_columns; } add_filter('manage_upload_sortable_columns', 'make_file_size_column_sortable'); function make_file_size_column_sortable($columns) { $columns['file_size'] = 'size'; return $columns; }