Adding custom columns and removing the default ones from WordPress Posts and Pages table

In many situations you may need to add custom columns to the default table provided in the WordPress ‘All Post’ and ‘All Page’ section.
So say you want to add a column that displays the value of a meta field ‘page_views’.
To add new columns to the post listing page put the following code in your active theme’s function.php file.

The above code will add the new column to the default table. Now its time to add content to this new column. The below code will output the value of each row for the newly created column.

If you want to remove any default column say the commments column use the below code

The main keyword in the above code is the filter manage_post_posts_columns which helps us in adding custom columns to the post’s table
The above codes are for Post’s listing page. For Page’s listing page just replace manage_posts_posts_columns with manage_page_posts_columns and manage_post_posts_custom_column with manage_page_posts_custom_column.

Leave a Reply

Your email address will not be published. Required fields are marked *