The manage_media_custom_column WordPress PHP action fires for each custom column in the Media list table. Custom columns are registered using the ‘manage_media_columns’ filter.
Usage
add_action('manage_media_custom_column', 'your_custom_function', 10, 2); function your_custom_function($column_name, $post_id) { // your custom code here }
Parameters
$column_name
(string) – Name of the custom column.$post_id
(int) – Attachment ID.
More information
See WordPress Developer Resources: manage_media_custom_column
Examples
Display file size in a custom column
Display the file size of each media item in a custom column.
add_filter('manage_media_columns', 'add_file_size_column'); add_action('manage_media_custom_column', 'display_file_size_column', 10, 2); function add_file_size_column($columns) { $columns['file_size'] = 'File Size'; return $columns; } function display_file_size_column($column_name, $post_id) { if ('file_size' === $column_name) { $file = get_attached_file($post_id); echo size_format(filesize($file)); } }
Display image dimensions in a custom column
Display the dimensions of each image in a custom column.
add_filter('manage_media_columns', 'add_image_dimensions_column'); add_action('manage_media_custom_column', 'display_image_dimensions_column', 10, 2); function add_image_dimensions_column($columns) { $columns['image_dimensions'] = 'Image Dimensions'; return $columns; } function display_image_dimensions_column($column_name, $post_id) { if ('image_dimensions' === $column_name) { $metadata = wp_get_attachment_metadata($post_id); if ($metadata) { echo $metadata['width'] . ' x ' . $metadata['height']; } } }
Display attachment type in a custom column
Display the attachment type (e.g. image, video, etc.) in a custom column.
add_filter('manage_media_columns', 'add_attachment_type_column'); add_action('manage_media_custom_column', 'display_attachment_type_column', 10, 2); function add_attachment_type_column($columns) { $columns['attachment_type'] = 'Attachment Type'; return $columns; } function display_attachment_type_column($column_name, $post_id) { if ('attachment_type' === $column_name) { $mime_type = get_post_mime_type($post_id); $mime_type_parts = explode('/', $mime_type); echo ucwords($mime_type_parts[0]); } }
Display the author of the attachment in a custom column
Display the author who uploaded the attachment in a custom column.
add_filter('manage_media_columns', 'add_author_column'); add_action('manage_media_custom_column', 'display_author_column', 10, 2); function add_author_column($columns) { $columns['author'] = 'Author'; return $columns; } function display_author_column($column_name, $post_id) { if ('author' === $column_name) { $author_id = get_post_field('post_author', $post_id); echo get_the_author_meta('display_name', $author_id); } }