How to Create Custom Taxonomy in WordPress

Taxonomy is a feature to group content like, posts, links in a structured way. For example, category and tag are the in-built taxonomies in WordPress to group posts. Category is a hierarchical taxonomy and the tag is an example of non-hierarchical taxonomy.

WordPress allows us to create custom taxonomies. It can be either hierarchical or non-hierarchical. It is introduced in version 2.3. Here we are going to see about how to create custom taxonomy in WordPress.


Register Custom Taxonomy

There is a function named register_taxonomy() to add and register our own custom taxonomy in WordPress. We have to hook this function to the init action in functions.php

Here is an example code for creating custom hierarchical taxonomy named Awards. The value we are giving in slug option will be used in the taxonomy page url. And the code is,

 * creating the custom taxonomy named 'Awards'
function create_custom_taxonomy() {
	register_taxonomy('awards', 'post', array(
		'labels' => ( 'Awards' ),
		'rewrite' => array(
			'slug' => 'awards', 
			'hierarchical' => true 
add_action( 'init', 'create_custom_taxonomy', 0 );

Taxonomy Terms

We can add more groups under taxonomy. These are called taxonomy terms. In this example we are registering the custom taxonomy for post. So we can see this under post menu in WordPress Admin. The screenshot is,


By using this menu, we can navigate to the page to add new terms to this custom taxonomy. This screenshot shows the page to manage custom taxonomy terms.


This PHP code tutorial was published on March 3, 2016.

↑ Back to Top