Last active
April 16, 2021 18:40
WordPress adding custom columns to custom post types
This file contains hidden or 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 | |
// 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