Black Friday/Cyber Monday Sale — ends 2nd December!

25% off all new licenses / 50% off all extensions & renewals

How to add custom admin columns for your WordPress custom post type

Adding your own custom admin columns can lead to some very interesting and powerful experiences for you website clients. A fantastic option for doing so can be the very popular Admin Columns Pro plugin but you may find yourself in a situation where you need something specific and need to roll your own solution. Doing so is simple as per the following snippet:

<?php
$post_type = 'my_post_type';
// Register the columns.
add_filter( "manage_{$post_type}_posts_columns", function ( $defaults ) {
$defaults['custom-one'] = 'Custom One';
$defaults['custom-two'] = 'Custom Two';
return $defaults;
} );
// Handle the value for each of the new columns.
add_action( "manage_{$post_type}_posts_custom_column", function ( $column_name, $post_id ) {
if ( $column_name == 'custom-one' ) {
echo 'Some value here';
}
if ( $column_name == 'custom-two' ) {
// Display an ACF field
echo get_field( 'my_acf_field', $post_id );
}
}, 10, 2 );

About the author

Phil Kurth is a web developer living in Melbourne, Australia. Phil has a long history of WordPress development and enjoys building tools to empower others in their web design/development practice.

When not working with the web, Phil is usually spending time with his two young sons or is out hiking through the Australian bush.

Good dev stuff, delivered.

Product news, tips, and other cool things we make.

We never share your data. Read our Privacy Policy

© 2016 – 2022 Hookturn Digital. All rights reserved.