manage_media_columns

Home » Hooks » manage_media_columns

The manage_media_columns hook is a filter that allows developers to add or remove columns from the Media Library table. It’s particularly useful for customizing the table to display additional information about media files or removing unnecessary columns to simplify the view.

This hook takes two arguments: the $columns array and the $attachment_id integer. The $columns array contains the default columns that WordPress displays in the Media Library table, with keys representing column slugs and values representing column names. Developers can modify this array to add or remove columns as needed. The $attachment_id integer represents the ID of the current media file being displayed in the table.

Here’s an example of how to use this hook to add a custom column to the Media Library table:

/**
 * Add a "File Size" column to the Media Library table.
 *
 * @param array $columns Array of default columns.
 *
 * @return array Modified array of columns.
 */
function wpse_add_media_columns( $columns ) {
    $columns['file_size'] = __( 'File Size', 'text-domain' );
    return $columns;
}
add_filter( 'manage_media_columns', 'wpse_add_media_columns' );

In this example, we’ve added a "File Size" column to the Media Library table by modifying the $columns array with the wpse_add_media_columns() function. The new column will display the file size of each media file in bytes. Developers can modify the function to add other types of custom columns as well.

Learn More on WordPress.org

Register an account to save your snippets or go Pro to get more features.