Skip to content

Instantly share code, notes, and snippets.

@mishterk
Created October 14, 2020 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mishterk/13e8ce20622b2dc5527f7ce8c9754dfd to your computer and use it in GitHub Desktop.
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.
<?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