How to Create a Custom Taxonomy in WordPress

How to Create a Custom Taxonomy in WordPress

Categories and tags are both taxonomies, ways to group content. When the built-in two are not enough (say, a “Genre” for books or a “Brand” for products), you register a custom taxonomy. Here is how.

Hierarchical or flat?

This is the first decision:

  • Hierarchical (like categories): terms can have parents and children, and the editor shows checkboxes. Use it for structured groupings such as Genre or Department.
  • Flat / non-hierarchical (like tags): a free-form comma list, no parents. Use it for loose labels such as Ingredients or Keywords.

You set this with the hierarchical argument.

Generate the code

  1. Open the Custom Taxonomy Generator.
  2. Set the key, singular and plural labels, and the post types it should attach to.
  3. Copy the register_taxonomy() code into functions.php or a plugin.

The tool produces the right label set for hierarchical or flat automatically.

Attaching it to post types

A taxonomy is registered against one or more post types (the third argument of register_taxonomy()). You can attach it to the built-in post, to your own custom post types, or to several at once. Register the taxonomy on the init hook, alongside or just after the post types it belongs to.

Useful options

  • show_in_rest: true to use it in the block editor and REST API.
  • show_admin_column: true adds a column to the post list so you can see terms at a glance.
  • rewrite: the URL slug for term archives.
  • public: whether term archives and the UI are visible.

Like custom post types, a new taxonomy with a custom slug needs rewrite rules refreshed. Visit Settings then Permalinks once and save.

Decide hierarchical or flat, name it, attach it to your post types, and flush permalinks. Your content is now organized exactly how you need.

← All posts