This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
manage_screen-id_columns filter
The dynamic portion of the hook name, $screen->id, refers to the ID of a specific screen. For example, the screen ID for the Posts list table is edit-post, so the filter for that screen would be manage_edit-post_columns.
To use manage_screen-id_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 modify_manage_screen-id_columns_defaults which takes 1 parameters and we registered using add_filter. The first parameter manage_screen-id_columns is name of the hook, The second parameter modify_manage_screen-id_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.
Sometime, you have to remove a registered hook so you can use remove_filter to remove manage_screen-id_columns filter.
Parameters
- $columns : (string[]) The column header labels keyed by column ID.
Below the 1 parameter is required to use this hook.
Live Example 1: Adding Custom Columns to a Custom Post Type
This example demonstrates how to add custom columns to a custom post type called “books”.
add_filter('manage_books_posts_columns', 'weplugins_book_cpt_columns'); function weplugins_book_cpt_columns($columns) { $new_columns = array( 'publisher' => __('Publisher', 'ThemeName'), 'book_author' => __('Book Author', 'ThemeName'), ); return array_merge($columns, $new_columns); }
Live Example 2: Modifying Default Columns
Below is an example of how you can modify the default columns of any screen.
function weplugins_modify_manage_screen_id_columns_defaults($columns) { // Update the $columns variable according to your website requirements and return this variable. You can modify the $columns variable conditionally too if you want. return $columns; } // add the filter add_filter("manage_screen-id_columns", "weplugins_modify_manage_screen_id_columns_defaults", 10, 1);
Live Example 3: Removing a Hook Callback
To remove a hook callback, use the example below.
remove_filter("manage_screen-id_columns", "weplugins_modify_manage_screen_id_columns_defaults", 10, 1);
Please make sure to provide the same callback function name, priority, and number of arguments while removing the hook callback.
Contact Us
If you’re having any trouble using this hook, please contact our WordPress Development Team and we’d be happy to assist you.
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.