Are you looking for a way to add your custom terms in an admin column? While there’s probably a plugin for this, we have created a quick code snippet that you can use to create custom terms admin column in WordPress.
Instructions:
All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:
// for pages add_filter('manage_pages_columns', 'term_columns_id', 5); add_action('manage_pages_custom_column', 'term_custom_id_columns', 5, 2); // for posts add_filter('manage_posts_columns', 'term_columns_id', 5); add_action('manage_posts_custom_column', 'term_custom_id_columns', 5, 2); function term_columns_id($defaults){ $defaults['wps_post_type'] = __('Term'); return $defaults; } function term_custom_id_columns($column_name, $id){ if($column_name === 'wps_post_type'){ echo the_terms( $id, 'TERM_NAME', '', ', ' ); } }
Make sure to change TERM_NAME
on this line echo the_terms( $id, 'TERM_NAME', '', ', ' )
in the above code to the name of your term. You will then see your terms displayed exactly the same way as you see categories displayed within the admin section.
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: 27 best WordPress business themes and how to create a WordPress donation form.
Comments Leave a Reply