Glossary WordPress Tutorial

What is a Taxonomy in WordPress: Detailed Guide

“Taxonomy” sounds like a word you would only hear in science class. Well, the term does come from biology, but we’re not here to talk about that. Simply speaking, WordPress taxonomy is used to group content.

In this article, we will explain what is WordPress Taxonomy, what are Custom Taxonomies and how to create them.

What is WordPress taxonomy?

WordPress Codex defines taxonomy as a grouping mechanism for all of your content. In short, it allows you to group your posts based on shared characteristics.

Let’s say that you have a website about movies. Chances are you want to group the movies based on genre. Taxonomy allows you to do just that, thus helping users to navigate your site.

Two of the most popular WordPress taxonomies to group posts are Categories and Tags. They both rest under the taxonomy umbrella. In total, there are four taxonomies in WordPress that you can use to group your posts.

Let’s take a look at each one.

1. Category

The category taxonomy lets you group your post into hierarchical categories. There are two different ways to group your posts via Categories.

The first way is to log in to your Dashboard and head to Posts -> Categories. There, you can define your categories, as well as add in the slug and define child categories.

adding categories from posts menu
Adding categories and setting the parent-child relation.

The second option is to head to Posts -> Add New. You can add categories directly from the panel next to your visual editor. While it is the easier option, it doesn’t let you define the slug and description.

adding categories from the visual editor

2. Tag

Tags are similar to categories – it groups your posts. However, it doesn’t have a hierarchical structure.

A tag is a single parameter that puts your similar posts together, but it focuses on smaller details of your content, rather than overall themes.

Let’s say that you want to create genres and subgenres for your movie website. You can do that by using category taxonomy, as it supports hierarchical structure. If you want to group movies of any genre with Brad Pitt as the main star, you can add tags.

Creating tags is similar to creating categories. You can do it either from Posts -> Tags or panel next to the visual editor. Slug and description can also be defined. We’ve covered about WordPress tag in detail here. Pay it a visit for further information.

adding tags from the visual editor
Adding tags from the visual editor

Protip: While tags are optional, categories are mandatory for your posts. Every post needs at least one category. By default, WordPress will automatically put your post under “Uncategorized” category.

The other 2 taxonomies are not visible to visitors. Although rarely used, they are still worth mentioning.

3. Link_category

This taxonomy lets you categorize your links. If you link to many sources on your posts, you’ll find this feature particularly useful.

4. Post_format

Post_format enables you to categorize your posts based on the types – videos, standard, audio, and more. You can find the panel next to your visual editor.

format taxonomy

Custom Taxonomies

At the right side of your visual editor, you can see the “Categories” and “Tags” label. What if you want to have your own taxonomy that says “People”? Here’s where custom taxonomy saves the day. You can customize your taxonomy to better accommodate your needs.

Customized people taxonomy

For example, think of a fitness website. Instead of having a general taxonomy that says “categories”, it would be better to have different taxonomies that say “Cardio” and “Floor Exercises”. Each taxonomy can be further modified with sub-categories like “Jogging”, “Intermittent running”, and “Crunches”. The same case goes with tags. You can have a tag that says “Fitness Instructor” instead of the default names.

How to create custom WordPress taxonomies

There are two different ways of creating Custom Taxonomies. You can do it with plugins, or you can do it through coding.

Using Plugins

Plugins make everything easy and creating a custom taxonomy is no exception. You don’t need any technical knowledge to do it.

The recommended plugins for creating custom taxonomies are Custom Post Types UI and Pods. Let’s try using the former for the example.

  1. Install and activate Custom Post Types UI
  2. Head to CPT UI -> Add/Edit Taxonomies
  3. Complete the box with your taxonomy name. In our case, we use “Floor Exercise”. Also, choose the post type on which you want to apply the new taxonomy.creating custom taxonomies with CTP UI
  4. Hit Add Taxonomy button at the bottom.
  5. If you head to Posts -> Add New, the new taxonomy will appear next to the visual editor.floor exercise new taxonomy on visual editor

You may notice that the new taxonomy is a tag called “Floor Exercise”. What if you want to create a category instead? Easy! Scroll down a bit and change Hierarchical to True.

changing tags to categories in CTP UI

The result will look like this:

floor exercise custom categories

You can also use the plugin to create Custom Post Types. Learn more about it here.

Adding code to functions.php

You should choose this method only if you are comfortable with coding. If not, ignore this tutorial and stick to using plugins only.

For advanced users, you only need to add a few lines of the functions.php file of your theme’s directory. Please be aware that the codes for the hierarchical taxonomy are different from the non-hierarchical one.

Take a look at the example below.

Hierarchical taxonomy (category):

//hook into the init action and call create_book_taxonomies when it fires
add_action( 'init', 'create_topics_hierarchical_taxonomy', 0 );

//create a custom taxonomy name it topics for your posts
function create_topics_hierarchical_taxonomy() {

// Add new taxonomy, make it hierarchical like categories

//first do the translations part for GUI
 $labels = array(
   'name' =_x( 'Topics', 'taxonomy general name' ),
   'singular_name' =_x( 'Topic', 'taxonomy singular name' ),
   'search_items' =__( 'Search Topics' ),
   'all_items' =__( 'All Topics' ),
   'parent_item' =__( 'Parent Topic' ),
   'parent_item_colon' =__( 'Parent Topic:' ),
   'edit_item' =__( 'Edit Topic' ),
   'update_item' =__( 'Update Topic' ),
   'add_new_item' =__( 'Add New Topic' ),
   'new_item_name' =__( 'New Topic Name' ),
   'menu_name' =__( 'Topics' ),
 );  

// Now register the taxonomy
 register_taxonomy('topics',array('post'), array(
   'hierarchical' =true,
   'labels' =$labels,
   'show_ui' =true,
   'show_admin_column' =true,
   'query_var' =true,
   'rewrite' =array( 'slug' = 'topic' ),
 ));
}

Non-hierarchical taxonomy (tag):

//hook into the init action and call create_book_taxonomies when it fires
add_action( 'init', 'create_topics_hierarchical_taxonomy', 0 );

//create a custom taxonomy name it topics for your posts
function create_topics_hierarchical_taxonomy() {

// Add new taxonomy, make it hierarchical like categories

//first do the translations part for GUI
 $labels = array(
   'name' =_x( 'Topics', 'taxonomy general name' ),
   'singular_name' =_x( 'Topic', 'taxonomy singular name' ),
   'search_items' =__( 'Search Topics' ),
   'all_items' =__( 'All Topics' ),
   'parent_item' =__( 'Parent Topic' ),
   'parent_item_colon' =__( 'Parent Topic:' ),
   'edit_item' =__( 'Edit Topic' ),
   'update_item' =__( 'Update Topic' ),
   'add_new_item' =__( 'Add New Topic' ),
   'new_item_name' =__( 'New Topic Name' ),
   'menu_name' =__( 'Topics' ),
 );  

// Now register the taxonomy
 register_taxonomy('topics',array('post'), array(
   'hierarchical' =true,
   'labels' =$labels,
   'show_ui' =true,
   'show_admin_column' =true,
   'query_var' =true,
   'rewrite' =array( 'slug' = 'topic' ),
 ));
}

To show the new taxonomy in your visual editor, open single.php from Editor and copy this code:

the_terms( $post-ID, 'topics', 'Topics: ', ', ', ' ' );

That’s it! If the process is done correctly, a new taxonomy called “Topic” will appear on your visual editor.

Conclusion

WordPress Taxonomy is used to group your content. You can use categories for broad topics, and tags for details in your text. You can also create custom taxonomies using plugins or functions.php file.

Correctly utilising WordPress taxonomies will help boost your website’s user experience.

About the author

Herawan Dwika P.

A Psychology and Marketing graduate, Dwika possesses a solid mix of empathy and good eyes for opportunities that lead him towards earning years of experience with WordPress, Linux, and Hosting. When he's not sharing his knowledge with others, Dwika works on his social platform, promoting humanity through the web. He's also a movie enthusiast. He takes them very, very seriously.

Add Comment

Click here to post a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get Exclusive Content

Join thousands of webmasters who get our free newsletter with tips on how to drive more traffic and revenue to their websites!

Please wait...

Thank you for sign up!

More in Glossary, WordPress Tutorial
What is CDN? Content Delivery Network Explained
Close