The manage_media_custom_column
hook is a WordPress filter used to modify the custom column in the media library. When working with WordPress, you can create custom columns to display additional information about the media files in the media library.
This hook is called when the custom column is being rendered. It takes two parameters: the column name and the attachment ID. You can use these parameters to retrieve and display custom data for the media file.
The manage_media_custom_column
hook is useful when you want to display custom information about your media files in the media library. For example, you might want to display the date the media file was last modified or the author who uploaded the media file.
Here’s an example of how you can use the manage_media_custom_column
hook to display the date a media file was last modified:
function my_custom_media_columns($column_name, $id) {
if ($column_name === 'last_modified') {
$last_modified = get_post_modified_time('F j, Y g:i a', false, $id, true);
echo $last_modified;
}
}
add_action('manage_media_custom_column', 'my_custom_media_columns', 10, 2);
In this example, we are checking if the custom column name is last_modified
, then using the get_post_modified_time
function to retrieve the last modified date and time of the attachment. Finally, we are outputting the result using the echo
statement.
By using the manage_media_custom_column
hook, you can easily add custom columns to the media library and display additional information about your media files.