Register a custom post type with full labels, REST API support, archive page, and featured image. Production-ready with proper i18n.
Back to Snippets
php
• 21 lines
PHP
Register Custom Taxonomy with Hierarchical Terms
Register a hierarchical custom taxonomy with full labels, REST API support, and admin column. Attach it to any custom post type.
Snippet Stats
Lines
21
Characters
1,028
Read
1 min
/**
* Register 'project_type' taxonomy for the portfolio CPT.
*/
add_action( 'init', function(): void {
register_taxonomy( 'project_type', array( 'portfolio' ), array(
'labels' => array(
'name' => __( 'Project Types', 'theme-domain' ),
'singular_name' => __( 'Project Type', 'theme-domain' ),
'search_items' => __( 'Search Project Types', 'theme-domain' ),
'all_items' => __( 'All Project Types', 'theme-domain' ),
'parent_item' => __( 'Parent Project Type', 'theme-domain' ),
'parent_item_colon' => __( 'Parent Project Type:', 'theme-domain' ),
'edit_item' => __( 'Edit Project Type', 'theme-domain' ),
'add_new_item' => __( 'Add New Project Type', 'theme-domain' ),
),
'hierarchical' => true,
'show_in_rest' => true,
'show_admin_column' => true,
'rewrite' => array( 'slug' => 'project-type' ),
) );
} );
Found an issue with this snippet? Help us improve by reporting it. Report it →