Search

How to Create Custom Taxonomy in WordPress (Without Plugin)

Taxonomy is a powerful feature that allows users to organize and structure content more efficiently. It enables the creation of custom classifications or grouping systems, which can be beneficial for managing websites with diverse content.

WordPress provides two default taxonomies: categories and tags. Categories offer a broad method of organizing content into hierarchical groups, while tags provide a more flexible way to assign descriptive keywords to content items. However, there are situations where these default taxonomies may not be sufficient to meet specific website requirements.

Why Use Custom Taxonomy?

This is where custom taxonomies come into play. They allow WordPress users to create their own unique classifications tailored to their website’s needs. By defining custom taxonomies, content creators gain greater control over how their content is organized, making it easier for visitors to navigate and locate specific information.

custom taxonomies facilitate better content management. They enable content creators to assign specific attributes or characteristics to their content items. For instance, a photography website could create a custom taxonomy for photo genres such as landscapes, portraits, or wildlife. By assigning the appropriate taxonomy term to each image, it becomes easier to filter and showcase specific types of photographs across the site.

In this tutorial, we will show you how to create a custom taxonomy without using any plugins. Let’s check it out!

Creating the Custom Taxonomy

To create a custom taxonomy without relying on a plugin, we will utilize the register_taxonomy() built-in WordPress function in a PHP code snippet. To simplify things, we will add the code directly to the functions.php file from the active theme which can be accessed by going to AppearanceTheme File Editor from your WordPress dashboard (if you use a block theme, you can find Theme File Editor under the Tools menu).

Before you start adding the snippets to your theme files, you might want to back up your site to avoid breaking your theme. Or, you can use a child theme or create a plugin yourself for the snippets to avoid losing your changes when you update or change your theme.

For this tutorial example, we will create a “Collections” custom taxonomy and assign it to the “Shoes” post type which we’ve created before in creating a custom post type tutorial.

Once youre ready, place the following code at the bottom of the file on your editor.

add_action('init', 'register_custom_taxonomy');

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

    $args = array(
        'hierarchical'      => true, // make it hierarchical (like categories)
        'labels'            => $labels,
        'show_ui'           => true,
        'show_admin_column' => true,
        'query_var'         => true,
        'show_in_rest' => true,
        'rewrite'    => array('slug' => 'Collection'),
    );

    register_taxonomy('Collections', 'wpp_shoe', $args); // Register the Taxonomy
}

After you’ve added the code to the file and make sure the custom taxonomy is assigned to the desired post type ( wpp_shoe in this case), save the changes by clicking the Update File button.

Now, you can find the newly created custom taxonomy under the assigned post type on your WordPress dashboard like follow.

The Bottom Line

Custom taxonomies are a valuable tool for content creators as they offer greater control over the organization of their content. By creating a custom post type, it is highly likely that a custom taxonomy will also be created to complement it. This combination allows visitors to navigate and locate specific information more easily thus enhancing the overall user experience.

This page may contain affiliate links, which help support our project. Read our affiliate disclosure.
Picture of Hendri Risman

Hendri Risman

Hendri is a WordPress expert and a writer staff at WPPagebuilders. He writes solutions on how to get things fixed in WordPress a lot. Mostly without involving a plugin.
Want to save yearly expense up to $219? why not?

Leave a Comment