Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use manage_media_columns filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
November 20, 2022
5 minutes read

manage_media_columns filter

Filters the Media list table columns.

To use manage_media_columns filter, first you have to register it using add_filter. You can write this code into functions.php of your activated theme or in a custom WordPress Plugin.

We at WePlugins always prefer to create a custom WordPress Plugin while using hooks so nothing breaks when you update your WordPress Theme in the future.

In the below live example, we have defined a function weplugins_modify_manage_media_columns_defaults which takes 2 parameters and we registered using add_filter. The first parameter manage_media_columns is name of the hook, The second parameter weplugins_modify_manage_media_columns_defaults is name of the function which need to be called, third parameter is the priority of calling the hook if same hook is used multiple times and the last parameter is the number of arguments (if any) to be passed in the registered function.

Sometimes, you have to remove a registered hook so you can use remove_filter to remove manage_media_columns filter.

Parameters

    Below are the 2 parameters required to use this hook.

  • $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.

Live Example 1: Adding a custom column

Below is an example of how you can use this hook to add a custom column.

function weplugins_modify_manage_media_columns_defaults($posts_columns, $detached) { 
    // Add a new column
    $posts_columns['custom_column'] = 'Custom Column';

    return $posts_columns; 
}
// add the filter
add_filter("manage_media_columns", "weplugins_modify_manage_media_columns_defaults", 10, 2);

Live Example 2: Modifying existing columns

This example demonstrates modifying the existing columns.

function weplugins_modify_manage_media_columns_defaults($posts_columns, $detached) { 
    // Rename an existing column
    if(isset($posts_columns['title'])) {
        $posts_columns['title'] = 'Media Title';
    }

    return $posts_columns; 
}
// add the filter
add_filter("manage_media_columns", "weplugins_modify_manage_media_columns_defaults", 10, 2);

Live Example 3: Removing a column

Here is how you can remove an existing column.

function weplugins_modify_manage_media_columns_defaults($posts_columns, $detached) { 
    // Remove an existing column
    if(isset($posts_columns['author'])) {
        unset($posts_columns['author']);
    }

    return $posts_columns; 
}
// add the filter
add_filter("manage_media_columns", "weplugins_modify_manage_media_columns_defaults", 10, 2);

To remove a hook callback, use the example below.

remove_filter("manage_media_columns", "weplugins_modify_manage_media_columns_defaults", 10, 2);

Please make sure to provide the same callback function name, priority, and number of arguments while removing the hook callback.

Access Premium WordPress Plugins

Contact Us

If you need any customization or are having trouble using this hook, please contact our WordPress Development Team. We’d be happy to assist you.

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.