Woman writing in notebook sitting in front of bookcase

How to Create Custom Taxonomies in WordPress

Content in WordPress can usually be gathered into distinct groups. Most of your posts and pages will be assigned to a type of ‘taxonomy’ – i.e. a category or tag – that already exists. However, you might also need to create a custom WordPress taxonomy.

Fortunately, the process for doing this is straightforward. Knowing how to create and update taxonomies will enable you to better organize your site, and help visitors find what they’re looking for more quickly.

In this article, we’ll look at how to create a custom WordPress taxonomy. However, before that, let’s discuss what a taxonomy is in more detail!

What Is a WordPress Taxonomy?

A WordPress taxonomy is a way to organize posts and other content. The two most common types are categories and tags. Categories are designed for grouping similar posts together, while tags (much like hashtags) describe what a specific post contains.

Most WordPress websites use these built-in taxonomies for organizing content. This is useful to both you and your visitors, since it helps everyone find what they want more efficiently. What’s more, grouping your content this way can even benefit your site’s Search Engine Optimization (SEO).

How to Create a Custom Taxonomy With a Plugin

Categories and tags are great, but what if you want other ways to organize your content? As is standard for WordPress, there are both user-friendly and developer-friendly ways to create a custom taxonomy.

We’re going to cover the plugin approach first. The first step is to choose your desired tool. We’ll use the Pods plugin, based on its user reviews and ease of use. However, there are plenty of other options to choose from, such as Custom Post Type UI.

Step 1: Add a New Blank Taxonomy and Populate the Fields

To get started, you’ll want to install and activate the plugin. Once you’ve done that, head to the Pods Admin > Add New screen within your WordPress dashboard:

Pods Admin > Add New screen within your WordPress dashboard

Next, select Custom Taxonomy (like Categories or Tags) from the Content Type drop-down menu. You’ll also want to create a singular and plural name for your new taxonomy (for example, “Recipe” and “Recipes” respectively).

You’ll notice a hidden Advanced menu, but those options aren’t required. Once you’ve filled the necessary fields in, click on Next Step and head to the Configure screen.

Step 2: Assign and Save Your Taxonomy

From there, you’ll be brought back to the Edit Pods screen, where you’ll see a success message:

Edit Pods screen success message

This screen lets you customize your taxonomy further. You can make it hierarchical like a category, or assign it to a custom post type. We’ll display our new taxonomy under the Posts menu, just as with categories and tags.

To do the same, head to the Admin UI screen, and populate the Menu Name field:

populate the Menu Name field

Then we’ll go to the Advanced Options tab, and check the box next to Posts (post) in the Associated Post Types menu:

check the box next to Posts (post) in the Associated Post Types menu

Save your changes, and you’ll see your new taxonomy alongside the others, ready to use:

Save your changes, and you’ll see your new taxonomy alongside the others

With that, your new taxonomy is set up and ready to go.

How to Create a Custom Taxonomy With Code

If you’d rather not use a plugin, or if you’re a developer who finds the manual approach easier, you can create your custom taxonomies with code. The steps below are simple to implement, especially if you have previous experience navigating WordPress’ core files.

Step 1: Determine If You Want a Hierarchical or Non-Hierarchical Taxonomy

First, you’ll want to decide whether your taxonomy will be hierarchical or not. Here’s a quick summary of the differences:

  • Hierarchical. This lets you have parent and child terms, just as with categories. For example, you could have a parent term called Beginners, and child terms such as Plugins, Themes, and Marketing.
  • Non-Hierarchical. Like tags, this only lets you define one term to assign to content, without letting you create child terms.

This decision matters, since the code you’ll need is slightly different depending on your preference.

Step 2: Edit Your functions.php File

Regardless of your taxonomies’ nature, you’ll need access to your functions.php file. Before you begin:

Then you can log in to your WordPress website through SFTP, and look for your functions.php file. It should be within your primary theme’s folder. Open the file once you’ve found it, and add one of the following code snippets to the bottom, depending on whether you chose a hierarchical taxonomy or not.

Hierarchical:

// Hook into the init action and call create_book_taxonomies when it firesadd_action( 'init', 'create_subjects_hierarchical_taxonomy', 0 );// Create a custom taxonomy name for your postsfunction create_subjects_hierarchical_taxonomy() {// Add a new taxonomy and make it hierarchical, like Categories// Translate the GUI   $labels = array(    'name' => _x( 'Subjects', 'taxonomy general name' ),    'singular_name' => _x( 'Subject', 'taxonomy singular name' ),    'search_items' =>  __( 'Search Subjects' ),    'all_items' => __( 'All Subjects' ),    'parent_item' => __( 'Parent Subject' ),    'parent_item_colon' => __( 'Parent Subject:' ),    'edit_item' => __( 'Edit Subject' ),    'update_item' => __( 'Update Subject' ),    'add_new_item' => __( 'Add New Subject' ),    'new_item_name' => __( 'New Subject Name' ),    'menu_name' => __( 'Subjects' ),  );  // Register the taxonomy  register_taxonomy('subjects',array(‘post_type'), array(    'hierarchical' => true,    'labels' => $labels,    'show_ui' => true,    'show_in_rest' => true,    'show_admin_column' => true,    'query_var' => true,    'rewrite' => array( 'slug' => 'subject' ),  ));}

Non-Hierarchical:

// Hook into the init action and call create_topics_nonhierarchical_taxonomy when it firesadd_action( 'init', 'create_topics_nonhierarchical_taxonomy', 0 );function create_topics_nonhierarchical_taxonomy() {// Add Labels to the GUI  $labels = array(    'name' => _x( 'Topics', 'taxonomy general name' ),    'singular_name' => _x( 'Topic', 'taxonomy singular name' ),    'search_items' =>  __( 'Search Topics' ),    'popular_items' => __( 'Popular Topics' ),    'all_items' => __( 'All Topics' ),    'parent_item' => null,    'parent_item_colon' => null,    'edit_item' => __( 'Edit Topic' ),    'update_item' => __( 'Update Topic' ),    'add_new_item' => __( 'Add New Topic' ),    'new_item_name' => __( 'New Topic Name' ),    'separate_items_with_commas' => __( 'Separate topics with commas' ),    'add_or_remove_items' => __( 'Add or remove topics' ),    'choose_from_most_used' => __( 'Choose from the most used topics' ),    'menu_name' => __( 'Topics' ),  ); // Register the non-hierarchical taxonomy similar to a Tag  register_taxonomy('topics','books',array(    'hierarchical' => false,    'labels' => $labels,    'show_ui' => true,    'show_in_rest' => true,    'show_admin_column' => true,    'update_count_callback' => '_update_post_term_count',    'query_var' => true,    'rewrite' => array( 'slug' => 'topic' ),  ));}

You’ll want to change the placeholder names in the above code to whatever you’d like to use for your custom taxonomy. You can also change the post_type within the register_taxonomy function – generally this is going to be Posts, but your needs may vary.

Once you save your changes, you’ll need to do a little more work in order to display your taxonomies. However, before that, let’s discuss how to create custom taxonomies in WooCommerce.

How to Create a Custom Taxonomy in WooCommerce

The good news is that creating a custom taxonomy for WooCommerce products follows almost exactly the same process as the plugin approach outlined above. Of course, you’ll want to ensure that you have WooCommerce installed and products uploaded to your store before carrying those steps out. 

The only change required is what happens when you get to the Advanced Options screen. This time, instead of checking Posts (post), you’ll now check Products (product):

This time, instead of checking Posts (post), you’ll now check Products (product)

Once you save your changes, the taxonomy will be ready to use. Then, the final step is learning how to display the taxonomies you’ve created.

How to Display Taxonomies

If you’ve come this far, you’ll have all the skills necessary to display your taxonomies. This next set of steps involves adding some code and digging around within WordPress’ templates, so make sure to back up your site if you haven’t already.

Step 1: Decide Where the Code Should Be Displayed

For this step, you’ll need some knowledge of WordPress’ template hierarchy. This is because you’ll have to add lines of code to every template where you want your custom taxonomies to display.

Quite often, you’ll want to amend single.php, content.php, or another file within your theme’s template-parts folder. However, you could theoretically add your custom taxonomy to any template file.

If you’re struggling to find the template a specific page uses, the Which Template Am I plugin can get the job done by showing you the template path within your browser. Once you’ve made this decision, the final step is to add some code.

Step 2: Add Code to Where You Want Your Taxonomy Displayed

Next, you’ll again want to access your theme’s files via SFTP, and open the template you chose during the first step. From there, you‘ll have to find the spot in your file where the taxonomy should display, and paste in the following:

<?php the_terms( $post->ID, 'topics', 'Topics: ', ', ', ' ' ); ?>

Once you save your changes, you should see the taxonomy displayed on your WordPress website. Of course, you may need to tweak the placement slightly, but the link should still be clickable and the taxonomy registered.

Customize Your Site With WP Engine

Customizations within WordPress take many forms. In this article we’ve discussed taxonomies, but there are many other features you can add to your site to improve its User Experience (UX). 

WP Engine’s flexible assortment of plans gives you the freedom to create and customize your website to your own exacting standards. For more information, check out our website and see for yourself how we can help!

Get started.

Build faster, protect your brand, and grow your business with a WordPress platform built to power remarkable online experiences.