Register a Custom Taxonomy
A ready-to-edit example that registers a hierarchical "Project Type" taxonomy for the Portfolio post type.
Opens WPIDE on
Code
add_action( 'init', function () {
register_taxonomy( 'project_type', array( 'portfolio' ), array(
'labels' => array(
'name' => 'Project Types',
'singular_name' => 'Project Type',
'add_new_item' => 'Add New Project Type',
'edit_item' => 'Edit Project Type',
'all_items' => 'All Project Types',
),
'hierarchical' => true,
'show_admin_column' => true,
'show_in_rest' => true,
'rewrite' => array( 'slug' => 'project-type' ),
) );
} );
Notes
Change portfolio to the post type(s) the taxonomy belongs to, then visit Settings > Permalinks once.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.