How to Remove Certain Screen Options and Table Columns from post type in wp_list_table?

What you need is to modify the $columns variable that is used during list display which you can modify using the 'manage_posts_columns' and 'manage_pages_columns' hooks for post_type="post" and post_type="page", respectively. If you want to ignore custom post types you can inspect the 2nd parameter passed to 'manage_posts_columns' as I did in my example to show how.

So let’s assume you want to get rid of the “Comments” screen option and it’s associated column which you see in these screenshot for Posts and Pages, respectively:


Drop the following class into your theme’s functions.php file or in a plugin you might be building and this code will remove the “Comments” screen option and it’s associated column (Since this answer is similar to your other question, I added a "2" to the class name, hence in Michael_Ecklunds_Admin_Customizer2):

class Michael_Ecklunds_Admin_Customizer2 {
  function __construct() {
    add_action( 'manage_pages_columns', array( $this, 'manage_columns' ) );
    add_action( 'manage_posts_columns', array( $this, 'manage_columns' ), 10, 2 );
  }
  function manage_columns( $columns, $post_type="page" ) { //2nd param not passed for pages
    if ( in_array( $post_type, array( 'post', 'page' ) ) ) {
      // This is only for posts and pages, 'if (in_array(...))' just illustrates how.
      unset( $columns['comments'] );
    }
    return $columns;
  }
}
new Michael_Ecklunds_Admin_Customizer2();

And here’s what it looks like after you’ve added the above code to a WordPress 3.4 site:


Using the Zend debugger within PhpStorm here is the inspection of $columns within the 'manage_posts_columns' hook so you can see what values a default installation of WordPress 3.4 has for the Post edit list (I’ve circled the array indexes I referenced in my example, i.e. $columns['comments']:

Hopefully this is what you were looking for?

Leave a Comment