Created
October 14, 2020 21:47
-
-
Save mishterk/13e8ce20622b2dc5527f7ce8c9754dfd to your computer and use it in GitHub Desktop.
A quick snippet for registering custom admin columns for a post type in WordPress.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$post_type = 'my-post-type'; | |
add_filter( 'manage_' . $post_type . '_posts_columns', function ( $defaults ) { | |
$defaults['custom-one'] = 'One'; | |
$defaults['custom-two'] = 'Two'; | |
return $defaults; | |
} ); | |
add_action( 'manage_' . $post_type . '_posts_custom_column', function ( $column_name, $post_id ) { | |
if ( $column_name == 'custom-one' ) { | |
echo 'TODO'; | |
} | |
if ( $column_name == 'custom-two' ) { | |
echo 'TODO'; | |
} | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment