Skip to content

Instantly share code, notes, and snippets.

@Mativve
Last active April 16, 2021 18:40
Show Gist options
  • Save Mativve/73e7cf021a5dc63ca50f23e51a01ab64 to your computer and use it in GitHub Desktop.
Save Mativve/73e7cf021a5dc63ca50f23e51a01ab64 to your computer and use it in GitHub Desktop.
WordPress adding custom columns to custom post types
<?php
// Add the custom columns to the book post type:
add_filter( 'manage_<post_type>_posts_columns', 'set_custom_edit_<post_type>_columns' );
function set_custom_edit_<post_type>_columns($columns) {
unset( $columns['author'] );
$columns['column_name'] = __( 'Column name', 'text-domain' );
return $columns;
}
// Add the data to the custom columns for the <post_type> post type:
add_action( 'manage_<post_type>_posts_custom_column' , 'custom_<post_type>_column', 10, 2 );
function custom_<post_type>_column( $column, $post_id ) {
switch ( $column ) {
case 'column_name':{
// Variables
echo "TEXT"
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment