"I Know That Now: Keep Learning"

Sponsored by: Ubora PLC

Create a custom WordPress taxonomy for posts and pages

Posted by Dillon | 18th January 2018

Sometimes when building website using WordPress, the standard taxonomies Categories and Tags just aren’t enough, and you need to create more. WordPress has made creating your own taxonomy easy, and you can even add your custom taxonomies to pages too. To accomplish this we use the custom WordPress taxonomy function register_taxonomy().

Creating a custom WordPress taxonomy

In the snippet below, we create a new custom taxonomy called Services and add it to the Pages post type.

add_action( 'init', 'create_taxonomy' );
function create_taxonomy() {
    register_taxonomy(
        'Service',  
        'page',  
        array(
            'label' => 'Service',
            'hierarchical' => true,
        )
    );
}

Copy and paste the snippet into your functions.php file, which is located in the root directory of your theme.

Now, if you navigate to the WordPress admin area, and select pages, you will notice a new label called Services.

You can also read up on WordPress taxonomies here. Also, we provide a whole host of Web Development articles including code snippets to help you along your way.

Related Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *