# Register a Custom Taxonomy

> A ready-to-edit example that registers a hierarchical "Project Type" taxonomy for the Portfolio post type.

- Type: PHP
- Runs: Run everywhere
- Category: [Developer](https://wpide.com/library/category/developer/)
- Tags: developer, taxonomy, categories
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/register-custom-taxonomy/

## Code

```php
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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Register a Custom Taxonomy" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
