Skip to main content

wp scaffold taxonomy

Overview

Generate the register_taxonomy() PHP code for a custom taxonomy — with all labels, rewrite rules, REST API support, and post type association configured. Output directly to a plugin file or review it first in the terminal.

What It Does

wp scaffold taxonomy outputs a valid, complete register_taxonomy() function call that you can drop directly into your plugin or theme.

Syntax

wp scaffold taxonomy <slug> [OPTIONS]

Options

FlagDescription
SLUGTaxonomy key (e.g., genre, location)
--post_types=TYPESComma-separated post types to associate the taxonomy with
--label=LABELHuman-readable label (singular)
--textdomain=TDText domain for i18n
--themeWrite code to the active theme's functions.php
--plugin=PLUGINAppend code to a plugin file
--forceOverwrite existing

Basic Usage

wp scaffold taxonomy genre \
--post_types=book \
--label="Genre" \
--textdomain=my-plugin

Output (to terminal):

<?php
/**
* Registers the `genre` taxonomy,
* for use with 'book'.
*/
function genre_init() {
register_taxonomy( 'genre', [ 'book' ], [
'hierarchical' => false,
'public' => true,
'show_in_nav_menus' => true,
'show_ui' => true,
'show_admin_column' => false,
'query_var' => true,
'rewrite' => true,
'labels' => [
'name' => __( 'Genres', 'my-plugin' ),
'singular_name' => __( 'Genre', 'my-plugin' ),
'search_items' => __( 'Search Genres', 'my-plugin' ),
'popular_items' => __( 'Popular Genres', 'my-plugin' ),
'all_items' => __( 'All Genres', 'my-plugin' ),
'edit_item' => __( 'Edit Genre', 'my-plugin' ),
'update_item' => __( 'Update Genre', 'my-plugin' ),
'add_new_item' => __( 'Add New Genre', 'my-plugin' ),
'new_item_name' => __( 'New Genre Name', 'my-plugin' ),
'not_found' => __( 'No genres found.', 'my-plugin' ),
],
'show_in_rest' => true,
'rest_base' => 'genre',
'rest_controller_class' => 'WP_REST_Terms_Controller',
] );
}
add_action( 'init', 'genre_init' );

Write to Plugin

wp scaffold taxonomy location \
--post_types=portfolio \
--label="Location" \
--plugin=my-portfolio-plugin

Best Practices

  1. Use show_in_rest=true (set by scaffold default) so the taxonomy works in Gutenberg.
  2. Consider hierarchicaltrue for category-like taxonomies, false for tag-like.
  3. Pair with a CPT created by wp scaffold post-type.

Quick Reference

wp scaffold taxonomy <slug> --post_types=<type> --plugin=<plugin>

Next Steps