Adding Custom Columns To Different Post Screens

So you want to add custom columns to different posts or pages screen, perhaps even to a custom post type and you’ve stumbled with this article after a quick search on Google. If you are wondering whether or not this is even possible, it is; and WordPress makes it really simple to add and even remove custom columns.

Adding a new Custom Column to a Post Screen is a two step process.

  • Register the specific column or columns you want to add by using one of WordPress filters
  • Hooking into an action which will populate the column with the value we want

Adding Custom Columns To The Posts Screen

Let’s explore how to add custom columns to the posts screen by using the manage_posts_columns filter. In order to keep it simple, we are just going to add 2 columns, the Post ID and the Post thumbnail if available. Begin by registering these columns which are going to require an identifier for the column and a label. The identifier is what we’ll use later on to populate th column with any value we want.

// Register 2 custom columns
add_filter( 'manage_posts_columns' , 'register_posts_custom_columns', 10, 1 );
function register_posts_custom_columns( $columns ) {
    return array_merge( $columns,
            // Identifier               Label
            'post_id'           => __( 'ID' ),
            'post_thumbnail'    => __( 'Thumbnail' )

As you can see, the manage_posts_columns filter takes one parameter, which is an array of columns where the key is the column identifier and the value is the Label that’s display on the screen for the user to know what the column is. Notice that we are appending our two columns to the end of the array. Piece of cake, right?

The second part involves hooking into the manage_posts_custom_column action and running a few lines of code on the identifier we registered on step one, these were post_id and post_thumbnail.

// Render the values for each of our column
add_action( 'manage_posts_custom_column', 'render_posts_custom_columns', 10, 2 );
function render_posts_custom_columns( $column_identified, $post_id ) {
    // Switch to the Column Identifier
    switch( $column_identified ) {
        // If it happens to be the post_id column
        case 'post_id':
            // Luckily the Post ID is passed to the action so we can use it here
            echo $post_id;
        // Is it the Post Thumbnail column?
        case 'post_thumbnail':
            if( has_post_thumbnail( $post_id ) ) {
                echo get_the_post_thumbnail( $post_id, 'thumbnail' );
            } else {
                echo 'No Thumbnail Set';

Custom Columns For Pages

The same can be done to the Pages screen on the back-end of your WordPress website. The process is the same, the hooks are very similar in name and take the same number of parameters. Let’s go over this similar process but instead of outputting the ID or the Post Thumbnail which is not supported by default in WordPress, we are going to show the Page Template being used with the Page or Default if that’s the case.

// Register 1 custom column
add_filter( 'manage_pages_columns' , 'register_pages_custom_columns', 10, 1 );
function register_pages_custom_columns( $columns ) {
    return array_merge( $columns,
            // Identifier               Label
            'page_template'           => __( 'Page Template' ),

Display the value:

// Render the values for each of our column
add_action( 'manage_pages_custom_column', 'render_pages_custom_columns', 10, 2 );
function render_pages_custom_columns( $column_identifier, $page_id ) {
    switch( $column_identifier ) {
        case 'page_template':
            if( get_post_meta( $page_id, '_wp_page_template', true ) ){
                echo '<code>', get_post_meta( $page_id, '_wp_page_template', true ), '</code>';
            } else {
                echo '<code>', 'Default', '</code>';

This is what you get if the Page has a custom Page Template assigned to it.

Custom Columns On Custom Post Types

Last but not least, you can repeat the same steps for any custom post type you have registered in your WordPress site. You would use the following two hooks instead of the 4 we’ve seen before.

  • manage_$post_type_posts_columns
  • manage_$post_type_posts_custom_column.

All you have to do is replace the $post_type section in each of these with the name of your Custom Post Type, for example:

Book” Post Type would use manage_book_posts_columns and manage_book_posts_custom_column.

Product” Post Type would use manage_product_posts_columns and manage_product_posts_custom_column.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s