Create a custom taxonomy in WordPress: complete guide

In WordPress, taxonomies let you classify content in a flexible way. Beyond the built-in ones like categories and tags, you can create your own custom taxonomies to organize content however you need—such as “Regions”, “Topics”, “Ingredients”, and more.

In this article, you’ll learn how to create a custom taxonomy using code, understand the main available options, link it to a Custom Post Type (CPT), discover the URL structure used to display taxonomy terms, and see which theme file WordPress uses to render the archive page.

 

What is a custom taxonomy?

A custom taxonomy in WordPress is a way to group and classify content using terms you define. It’s useful to improve navigation, filtering, and organization of your site—especially when working with Custom Post Types.

 

How to create a taxonomy with register_taxonomy()

The register_taxonomy()function lets you register a new taxonomy in WordPress. It’s typically called inside the inithook.

Basic Example:

<?php
function registerRegionTaxonomy() {
    $labels = [
        'name'              => 'Regions',
        'singular_name'     => 'Region',
        'search_items'      => 'Search Regions',
        'all_items'         => 'All Regions',
        'edit_item'         => 'Edit Region',
        'update_item'       => 'Update Region',
        'add_new_item'      => 'Add New Region',
        'new_item_name'     => 'New Region Name',
        'menu_name'         => 'Regions'
    ];

    $args = [
        'labels'            => $labels,
        'public'            => true,
        'hierarchical'      => true, // true behaves like categories
        'show_ui'           => true,
        'show_in_rest'      => true, // important for Gutenberg support
        'show_admin_column' => true,
        'rewrite'           => [ 'slug' => 'region' ]
    ];

    register_taxonomy( 'region', [ 'post' ], $args );
}
add_action( 'init', 'registerRegionTaxonomy' );

This example creates a hierarchical taxonomy called Region associated with the postpost type.

 

Available register_taxonomy() options

Here’s a summary of the most useful options:

 

Option Description
labels Labels shown in the WordPress admin.
public Controls whether the taxonomy is visible on the frontend.
hierarchical true makes it work like categories, false like tags.
show_ui Displays the interface in the admin area.
show_in_rest Enables support for Gutenberg and the REST API.
show_admin_column Adds a column to the post type list table.
rewrite Sets the slug for friendly URLs.
query_var Enables query variable in URLs (?region=south).
meta_box_cb Lets you define a custom callback for the metabox UI.

 

What’s the URL to view taxonomy posts?

When you set the rewriteoption, WordPress generates a public URL for each term in the taxonomy. For example, if you register the regiontaxonomy with the slug region, and you have a term called south, the URL will be:

https://yoursite.com/region/south/

Visiting that URL will display all posts assigned to the southterm.

 

Which theme file renders the taxonomy archive?

When a user visits a URL like https://yoursite.com/region/south/, WordPress uses its template hierarchy to determine which theme file to load.

For a taxonomy named region, WordPress looks for the following files in this order:

taxonomy-region.php
taxonomy.php
archive.php
index.php

So if you want to customize the layout for the Region taxonomy, just create a file called taxonomy-region.phpin your theme.

Example of theme file structure:

/wp-content/themes/your-theme/
│
├── archive.php
├── index.php
├── page.php
├── single.php
├── taxonomy.php
└── taxonomy-region.php ← used for the “Region” taxonomy

 

Displaying the taxonomy in the frontend

To display the taxonomy terms associated with a post or CPT:

<?php
$terms = get_the_term_list( get_the_ID(), 'region', 'Region: ', ', ' );
if ( $terms ) {
    echo '<p>' . $terms . '</p>';
}

 

Creating custom taxonomies gives you full control over how you organize your WordPress content. In addition to improved navigation, you get clean, SEO-friendly URLs and automatic archive pages—which you can easily customize using templates like taxonomy-region.php.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to Top
0
Would love your thoughts, please comment.x
()
x