How to Create Custom Taxonomies in WordPress (2 Easy Ways)

After 15+ years building websites, I can tell you that custom taxonomies are one of the most useful yet underutilized features in WordPress.

If you want to take your content organization to the next level, implementing custom taxonomies is a must.

In this comprehensive guide, I‘ll show you exactly how to create, use, and display custom taxonomies on your WordPress site.

A Taxonomy 101 for WordPress Sites

First, let‘s quickly cover what taxonomies are in WordPress.

Taxonomies allow you to categorize and group content on your site. The two default WordPress taxonomies are:

  • Categories – For grouping posts and pages in a hierarchy.
  • Tags – For adding non-hierarchical keywords to posts.

These built-in taxonomies work fine for most basic websites.

However, on a more complex site, you may need to create custom structures for organizing content.

For example, an online magazine may want to sort articles by "Magazine Issue". An ecommerce site could use "Product Brand" for grouping products.

This is where custom taxonomies come in…

What Are Custom Taxonomies?

A custom taxonomy lets you create completely new ways of classifying and sorting WordPress posts, pages, and custom post types.

According to BuiltWith, over 15% of the top 10,000 WordPress sites use custom taxonomies. So they are commonly used on large and advanced sites.

Here are some examples of custom taxonomies:

  • Genres – For grouping books, movies, or music by genre.
  • Product Lines – For sorting products into different lines or brands.
  • Neighborhoods – For real estate sites to organize listings by location.
  • Difficulty – For tutorial sites to indicate beginner/intermediate/advanced topics.

And many more possibilities!

With custom taxonomies, you can build any content structure that makes sense for your site and goals.

The Benefits of Using Custom Taxonomies

Here are some specific benefits that implementing custom taxonomies can provide:

Better Organization

Taxonomies allow you to categorize content in ways that fit your particular site. Group products by brand, sort recipes by cuisine type, or segment news stories by source.

Enhanced Filtering and Navigation

Visitors can drill down to find exactly the type of content they want. And custom taxonomies integrated into menus improve navigation.

SEO Optimizations

Properly structured and labeled content results in better SEO and increased organic traffic over the long-term.

Customized Taxonomy Archive Pages

Control the look, layout, and design on each taxonomy term archive page with custom templates.

Works with REST API

Taxonomies integrate seamlessly with the WordPress REST API, allowing usage across other platforms.

Granular User Experiences

Let visitors subscribe to specific taxonomy terms via RSS to see only the content they care about.

As you can see, the benefits go well beyond basic content organization. Implemented properly, taxonomies can significantly improve a site‘s user experience, SEO, design, and API expansions.

Now let‘s dive into how to add custom taxonomies to your WordPress site.

How to Register a Custom Taxonomy in WordPress

When it comes to creating a custom taxonomy, you have two options:

  1. Use a plugin like Custom Post Type UI
  2. Manually register taxonomies in your theme code

Next, I‘ll explain both methods step-by-step:

Option 1: Using a Plugin to Add Taxonomies

For most users, a plugin is the easiest way to add custom taxonomies without touching code.

There are a few good taxonomy plugins, but my top recommendation is Custom Post Type UI. It‘s trusted by over 600,000 WordPress sites.

Here is how to create a taxonomy using Custom Post Type UI:

Step 1: Install and activate the plugin

First, install the plugin on your WordPress site. Then head to the "Plugins" menu and activate.

Step 2: Add new taxonomy

In your admin, go to CPT UI » Add/Edit Taxonomies to register a new taxonomy:

Custom Post Type UI add taxonomy

Step 3: Complete taxonomy fields

Here, you‘ll need to:

  • Enter descriptive taxonomy name and singular/plural labels
  • Choose a slug – this is used in permalinks
  • Pick associated post types to use this taxonomy
  • Select hierarchical or non-hierarchical

Step 4: Set taxonomy options

Scroll down further to configure settings like:

  • Publicly queryable
  • Show in REST API
  • Show admin column
  • And more

Step 5: Save your custom taxonomy

Finally, click "Add Taxonomy" to register it. Now you can start using it when creating content!

This plugin makes taxonomy registration a breeze. Within a few minutes, you can set up custom categories without coding.

Next, let‘s look at manually adding taxonomies…

Option 2: Manually Register Taxonomies in Code

For complete flexibility, you can directly register taxonomies in your theme using PHP code and the register_taxonomy() function.

Here is an example custom taxonomy registration:

add_action( ‘init‘, ‘register_movie_genre_taxonomy‘ );

function register_movie_genre_taxonomy() {

  $labels = array( 
    ‘name‘ => _x( ‘Genres‘, ‘taxonomy general name‘ ),
    ‘singular_name‘ => _x( ‘Genre‘, ‘taxonomy singular name‘ ), 
    // etc
  );

  register_taxonomy( ‘movie_genre‘, array( ‘movie‘ ), array(
    ‘hierarchical‘ => true,
    ‘labels‘ => $labels,
    // etc
  ) );

}

Let‘s break this down:

  • add_action() hook runs our taxonomy registration function.
  • register_taxonomy() defines the taxonomy details.
  • The first parameter (movie_genre) is the taxonomy name/slug.
  • Second parameter (movie) specifies associated custom post type(s).
  • Third parameter is taxonomy options array, like hierarchical, publicly queryable, etc.

Make sure to replace movie_genre and movie with your own taxonomy and post type names.

This would allow you to create a hierarchical "Genre" taxonomy for movies, with terms like Action, Drama, Comedy, etc.

See the codex documentation for all available taxonomy options.

Pro Tip: I recommend using a plugin like WPCode to add custom PHP code snippets. This avoids editing sensitive theme files directly.

Now that you know how to register custom taxonomies, let‘s go over how to display them.

How to Display Custom Taxonomies on Your WordPress Site

After registering a taxonomy, the next step is showing it on your site for visitors.

You have many options for displaying taxonomies:

Single Posts

Use a template tag like the_terms() to show taxonomy terms on individual posts:

<p>Genre: <?php the_terms( $post->ID, ‘movie_genre‘ ); ?></p> 

Taxonomy Archives

Each taxonomy term gets an archive page at a URL like example.com/taxonomy/term. List associated posts here.

Navigation Menus

Add taxonomy terms to your site‘s main menus or footer navigation for easy discovery.

Sidebars/Widgets

Display taxonomy terms in a sidebar widget to allow visitors to filter content.

REST API

Taxonomies integrate with the WordPress REST API. Expose them to other sites/apps.

Feeds

Let users subscribe to specific taxonomy term feeds via RSS.

Use the WordPress template hierarchy to determine which template files you need to edit.

Now let‘s go over some specific use cases and advanced features for getting the most out of custom taxonomies.

Advanced Usage of Custom Taxonomies

Custom taxonomies have tons of possibilities. Here are some more advanced ideas:

Hierarchical vs Non-Hierarchical Taxonomies

When registering a taxonomy, you can specify:

  • Hierarchical – Like categories, with parent/child terms.
  • Non-hierarchical – Like tags, no hierarchy between terms.

For example, a "Book Genre" taxonomy may be hierarchical – with Fiction, Non-Fiction, and Children‘s as parent terms.

Meanwhile, an "Author" taxonomy could be non-hierarchical, with terms like John Steinbeck, Ernest Hemingway, etc.

Choose the type that fits your content structure.

Granular Feeds for Users

One cool use is setting up granular RSS feeds for taxonomy terms.

For instance, a newspaper site could offer feeds for individual journalists. Or a podcast could have genre-specific feeds.

To do this, install the Custom Taxonomy Feeds plugin. Visitors can then subscribe to exactly the content they want.

Integrating with REST API

If you expose your site‘s API using the WordPress REST API, any custom taxonomies you create will be automatically available.

This allows programmatic access for mobile apps, JavaScript sites, etc.

For example, a weather app could consume weather data from a taxonomy called "Forecast Zones". Or a TV guide app could access show data tagged with "Network" and "Genre" taxonomies.

The possibilities are endless!

Conclusion

As you can see, custom taxonomies are incredibly useful on WordPress sites – both for your visitors and for developers.

Implementing thoughtful content structures using custom taxonomies takes your site to the next level.

I hope this guide provided lots of ideas and actionable steps for adding taxonomies to your WordPress site! Let me know if you have any other questions.

Written by Jason Striegel

C/C++, Java, Python, Linux developer for 18 years, A-Tech enthusiast love to share some useful tech hacks.