Connect with us

WP Superstar

Adding Custom Columns To Different Post Screens

Adding Custom Columns To Different Post Screens

WordPress

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.

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?

Here is what we’ve got so far:

Adding Custom Columns To The Posts Screen

Adding Custom Columns To The Posts Screen

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.

The result can be seen below:

Render the values for each of our column

Render the values for each of our column

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.

Custom Columns For Pages

Custom Columns For Pages

Display the value:

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

Render the values for each of our column

Render the values for each of our column

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.

To me, WordPress is a system to which versatility and power come naturally. Over the last thirteen years of my life, I have seen WordPress evolve from a simple blogging platform into the leading CMS that powers more than 27% of the Internet. My experience is broad, ranging all the way from writing WordPress plugins to creating WordPress themes based on PSD files. I am a master of developing and deploying membership sites powered by WooCommerce, WooCommerce Memberships, and WooCommerce Subscriptions.

Comments

More in WordPress

To Top