Create a custom WordPress taxonomy for posts and pages

By Dillon Smart · · · 0 Comments

Sometimes when building a website using WordPress, the standard taxonomies Categories and Tags just aren’t enough, and you need to create more. Let’s learn how to create our own custom WordPress taxonomy.

Wordpress Post Taxonomy

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

To create a new WordPress Taxonomy, we will need to use the register_taxonomy function which comes built-in to WordPress.

WordPress has hundreds of these functions you can use to customize your WordPress website. If you are unfamiliar with making changes to the code of your WordPress theme, or unfamiliar with PHP the programming language WordPress is built in, check out this post which explains and answers the question what is PHP?

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', // the name of your new taxonomy
            'hierarchical' => true,
        )
    );
}

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

Notice in the code the comment next to ‘label’. You can change this to whatever suits your needs best. In this case, I want to create a new WordPress Taxonomy called Services.

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

Conclusion

You can also read up on WordPress taxonomies here.

PHPWordPress

0 Comment

Was this helpful? Leave a comment!

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

Laravel php artisan make:auth command not defined

Updated 11th August 2022

Laravel 6.0 LTS came with a lot of changes to the framework, apart from moving the the new Semantic Versioning, Laravels famous php artisan make:auth command was dropped. php artisan make:auth Before the Laravel make:auth command would create all the Migrations, Models, Controllers and Routes needed to easily setup an authenticatable application in seconds. However,

How to use Microsoft Graph API with Laravel

Updated 1st January 2024

Microsoft Graph is a gateway to data and intelligence within Microsoft 365. Microsoft Graph is great to build apps for organizations and consumers using the vast amount of data stored in Microsoft 365. In this post, we are going to integrate with Microsoft Graph API in Laravel to get all users assigned to your tenant.

Alternative ways of doing the same things in Laravel

Updated 29th March 2022

Laravel is a large framework, with contributions coming from almost 2000 developers worldwide. Over its 10 year journey, there have been additions to the framework to do the same thing, only shorter. In this post, I have highlighted some alternative ways of doing the same things in Laravel. How to get the authenticated users id