Better Content Organization with Custom Taxonomies in WordPress

Out of the box, WordPress offers you two ways to categorize your content: categories, and tags (the latter of which was introduced in WordPress 2.3). Tags and categories are called taxonomies, which is just a fancy word for a way of organizing things. Categories are used more broadly, while tags are used to address specific points in your posts. For instance, a movie review for The Godfather might fall into the category of “Reviews”, but be tagged with: “Gangster”, “Classic”, “Movie Review”, and “70s Film”.

Like most things in WordPress, the taxonomies are customizable, and adding custom taxonomies is fairly simple.

Tutorial Requirements

This tutorial assumes you have a WordPress site setup, and can access the files on the server, specifically the functions.php file within your theme. I would recommend completeing this tutorial on a locally installed version of WordPress rather than on your live website.

Estimated Completion Time: < 30 Minutes
Difficulty: Medium

Benefits of  Custom Taxonomies

So why would you want to use custom taxonomies in the first place? Let’s go back to our earlier example of the review of The Godfather. If your site posted a lot of different reviews, it would make sense for you to categorize them in a variety of ways. Here are a couple examples:

  • Genre
  • Directory
  • Studio
  • Awards
  • Actors & Actresses
  • Rating
  • Letter Grade

Now, you could use tags for all these, but pretty soon your site would be a mess of hundreds or even thousands of tags. A better way to do this would be to add a custom taxonomy for the various items you would use to categorize all your reviews. This makes more logical sense, and allows you to organize and interlink you content on any number of criteria while maintaining an easily readable front-end for your users.

How to Setup Custom Taxonomies

Let's add some custom taxonomies to WordPress!

To setup custom taxonomies, you’ll need to either edit your theme’s functions.php file, or create a plugin. For this tutorial, we’ll be using functions.php. To get started, simply copy the below into functions.php.

add_action( 'init', 'add_genre_taxonomy' );
function add_genre_taxonomy() {
 $labels = array(
    'name' => _x( 'Genres', 'taxonomy general name' ),
    'singular_name' => _x( 'Genre', 'taxonomy singular name' ),
    'search_items' =>  __( 'Search Genres' ),
    'all_items' => __( 'All Genres' ),
    'parent_item' => __( 'Parent Genre' ),
    'parent_item_colon' => __( 'Parent Genre:' ),
    'edit_item' => __( 'Edit Genre' ),
    'update_item' => __( 'Update Genre' ),
    'add_new_item' => __( 'Add New Genre' ),
    'new_item_name' => __( 'New Genre Name' ),
    'menu_name' => __( 'Genre' )

 $args = array(
    'hierarchical'        => true,
    'labels'              => $labels,
    'show_ui'             => true,
    'show_admin_column'   => true,
    'query_var'           => true,
    'rewrite'             => array( 'slug' => 'genre' )

register_taxonomy( 'genre', 'post', $args );

Now, when you add a new post, you’ll see an area to add the “Genre”. I added a few to better illustrate what we’re trying to accomplish here.

Our new custom taxonomy: genre

Breaking Down the Code:

It’s great that this works and all, but let’s take a look at a few of the more interesting pieces of the code see we can see how they work, and how you can tweak them to add your own taxonomies.

Right at the start we see: add_action( ‘init’, ‘add_genre_taxonomy’ ). This tells WordPress to run the add_genre_taxonomy function, when WordPreess initializes.

Next we get function add_genre_taxonomy(), which defines the function that will setup our Genre taxonomy.

After that, get get an array of the labels used for our taxonomy. These are pretty self-explanatory.

Below the labels are the arguments used in our function. Let’s break those down:

  • hierarchical: “True” if the taxonomy is hierarchical, which means it can have children (think categories and sub-categories). “False” if it’s non-hierarchical (like a tag). By default, this is set to “False”.
Setting "hierarchical" to "false" will give us a tag-like set of taxonomies

Setting “hierarchical” to “false” will give us a tag-like set of taxonomies

  • labels: This is an array defines our labels. As you can see, we set it up with a variable that contains the information we setup earlier
  • show_ui: “True” generates a default user interface for this taxonomy. This defaults to “True” so long as the taxonomy is public, which it is by default.
  • show_admin_column: “True” adds a column to the posts (or whatever post type supports your taxonomy) page to display the taxonomy. This defaults to “False”.
  • query_var: “False” will disable queries through WP_Query. This defaults to $taxonomy, which is your custom taxonomy’s name.
  • rewrite: “False” will turn off pretty-permalinks. rewrite defaults to “True”.

There are some other arguments you can use here as well. For more information, check out “register_taxonomy” entry in the WordPress Codex.

Finally, we have register_taxonomy( ‘genre’, ‘post’, $args ). This does three things. First, it gives the taxonomy it’s slug name (“genre”). Second, it identifies which post types can use the taxonomy. And finally, it passes in our array of arguments.

How to Display Custom Taxonomies

Now that we have our genre taxonomy created, we need to actually display it on our post. To do this, we’ll be working with the below function:

<?php get_the_term_list( $id, $taxonomy, $before, $sep, $after ) ?> 

This will return a string of taxonomy terms that are associated with a particular post ID.  You can use the $before, $sep, and $after fields to put content before, between, and after each of the taxonomy terms.

For examples, let’s say that we wanted to display our list of genres as a bulleted list at the end of our post. We could add the following:

<?php echo get_the_term_list(
      '</li>' )

This creates an unordered list, precedes each term with a new list item, and ends each item by closing the list item tag. Simply place this in the appropriate place in your template file(s) (e.g. single.php) and it will display a bulleted list of the genres you added to this particular post.


Custom taxonomies are a powerful tool, especially for sites with a lot of information to be organized. This was a pretty specific example, but you should be able to tweak the code here to adapt it to whatever sort of classification system you want. If you have any questions, please don’t hesitate to ask.

In this tutorial we covered the following:

One Response to “Better Content Organization with Custom Taxonomies in WordPress”

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>