Removing columns from pages & posts such as Type, Author & Comments

22 January, 2015 by Tom Elliott

Modifying columns in WordPress admin can be a great way to customise and streamline content management within WordPress. In this post, I’ll run through a few examples of how we can use two WordPress hooks: manage_pages_columns and manage_posts_columns to remove columns from page, post and custom post type views in the WordPress admin.

For example, I often like to remove the ‘Type’ column in WordPress admin on all pages and post types. The Type column (post_type field) has always seemed unnecessary. We know what page/post type we are viewing as it is displayed at the top of the admin view and repeating this on each row is superfluous.

Similarly, the ‘Comments’ column and count enabled by default on posts and pages is usually useful to display for blog posts but rarely used on regular pages.

Removing columns from pages

Here is the code to remove the ‘Type’ heading from WordPress admin, using the manage_pages_columns hook and calling a function named ‘custom_pages_columns’. You will need to add this to your theme’s functions.php

add_filter( 'manage_pages_columns', 'custom_pages_columns' );

function custom_pages_columns( $columns ) {
  unset(
    $columns['post_type']
  );

  return $columns;
}

If you want to remove multiple columns such as comments or author fields, we can change the unset array to include the names of the column fields as below.

unset(
   $columns['comments'],
   $columns['author'],
   $columns['post_type']
);

If your functions.php file has already used the manage_pages_columns hook, you should be able to use these hooks twice or merge the unset lines within the existing function.

Removing columns from posts and custom post types.

For posts and custom post types, we use and manage_posts_columns. This is a little different to manage_pages_columns as it can be used for any custom post types in addition to regular posts.

We can use the $post_type parameter which is past to the function to remove different columns, depending on the post type using a switch statement.

For example, if you had a custom post type named ‘gallery’, we can remove columns specific to the gallery post type. In the code example below, we are removing Type and Tags columns from regular posts and Type and Author fields from gallery post types.


add_filter( 'manage_posts_columns', 'custom_post_columns', 10, 2 );
function custom_post_columns( $columns, $post_type ) {
 
  switch ( $post_type ) {    
   
    case 'post':
    unset(
      $columns['tags'],
      $columns['post_type']
    );
    break;

    case 'gallery':
    unset(
      $columns['post_type'],
      $columns['author']
    );
    break;
    
  return $columns;
}


Adding a featured image column for posts & pages in WordPress »
19 ways to improve the speed of your WordPress website »
Creating a manual list of related posts in WordPress »
10 advantages of developing bespoke WordPress themes »
Adding font icons to WordPress custom post types »


2 Comments

  • John Fridinger says:

    Thank you for this, much appreciated… 🙂

  • Great tutorial.
    Please be aware that there is also a filter for custom post types that runs later

    // This one runs first
    add_filter( ‘manage_posts_columns’, ‘custom_post_columns’, 10, 2 );

    // This one runs at the end
    add_filter( ‘manage_{$post_type}_posts_columns’, ‘custom_post_columns’, 10, 2 );

    Besides you can better aim for specific post types this way and you are sure that other custom columns are added here so you can remove those too if you like.

    There is also a free plugin called Admin Columns that allows you to create and remove these columns with an interface without the need to code 🙂

    The pro version of this plugin allows you to sort and filter on those columns and even use inline edit for the values in the columns. https://www.admincolumns.com/