Using WordPress ‘default_hidden_columns’ PHP filter

The default_hidden_columns WordPress PHP filter allows you to modify the default list of hidden columns in the admin area.

Usage

add_filter('default_hidden_columns', 'my_custom_hidden_columns', 10, 2);

function my_custom_hidden_columns($hidden, $screen) {
  // your custom code here
  return $hidden;
}

Parameters

  • $hidden (string[]): Array of IDs of columns hidden by default.
  • $screen (WP_Screen): WP_Screen object of the current screen.

More information

See WordPress Developer Resources: default_hidden_columns

Examples

Hiding a specific column on all screens

Hide the ‘comments’ column for all screens:

function hide_comments_column($hidden, $screen) {
  $hidden[] = 'comments';
  return $hidden;
}
add_filter('default_hidden_columns', 'hide_comments_column', 10, 2);

Hiding a custom column for a specific post type

Hide the ‘my_custom_column’ for the ‘book’ post type:

function hide_custom_column_for_books($hidden, $screen) {
  if ($screen->post_type == 'book') {
    $hidden[] = 'my_custom_column';
  }
  return $hidden;
}
add_filter('default_hidden_columns', 'hide_custom_column_for_books', 10, 2);

Unhiding a default hidden column

Unhide the ‘author’ column for all screens:

function unhide_author_column($hidden, $screen) {
  if (($key = array_search('author', $hidden)) !== false) {
    unset($hidden[$key]);
  }
  return $hidden;
}
add_filter('default_hidden_columns', 'unhide_author_column', 10, 2);

Hiding multiple columns

Hide the ‘categories’ and ‘tags’ columns for all screens:

function hide_multiple_columns($hidden, $screen) {
  $hidden[] = 'categories';
  $hidden[] = 'tags';
  return $hidden;
}
add_filter('default_hidden_columns', 'hide_multiple_columns', 10, 2);

Hiding columns based on user roles

Hide the ‘author’ column for users with the ‘subscriber’ role:

function hide_author_column_for_subscribers($hidden, $screen) {
  if (current_user_can('subscriber')) {
    $hidden[] = 'author';
  }
  return $hidden;
}
add_filter('default_hidden_columns', 'hide_author_column_for_subscribers', 10, 2);