Back to Snippets

Register Custom Taxonomy with Hierarchical Terms

PHP Custom Post Types April 6, 2026

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
php • 21 lines
/**
 * 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 →

Related Snippets

View all
PHP
Register a custom post type with full labels, REST API support, archive page, and featured image. Production-ready with proper i18n.

Register a Custom Post Type with REST API Support