Create custom taxonomy in wordpress

Developerking
1 min readJan 13, 2023

To create a custom taxonomy in WordPress, you can use the register_taxonomy() function. Here are the steps to create a custom taxonomy:

  1. Create a new plugin or add the code to your theme’s functions.php file.
  2. Use the register_taxonomy() function to create a new custom taxonomy.
function create_custom_taxonomy() {
$args = array(
'label' => __( 'Custom Taxonomy' ),
'rewrite' => array( 'slug' => 'custom_taxonomy' ),
'hierarchical' => true,
);
register_taxonomy( 'custom_taxonomy', 'custom_post_type', $args );
}
add_action( 'init', 'create_custom_taxonomy' );

3. Replace ‘custom_taxonomy’ in the code with the desired name for your custom taxonomy.

4. Replace ‘Custom Taxonomy’ in the ‘label’ with the desired name for your custom taxonomy in the WordPress admin.

5. Replace ‘custom_post_type’ with the post type name you want to associate the custom taxonomy with.

6. Save the changes and activate the plugin or refresh your site.

The custom taxonomy will now be available in the WordPress admin under the “Posts” menu and will be associated with the post type you specified. It is recommended to test the changes on a development environment before pushing it to live site and also take a backup of your site before making any changes.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Developerking
Developerking

Written by Developerking

We are creating the world's largest community of developers & Share knowledgeable contents , So Stay Tuned & Connect with us !! Become a Dev King Member.

No responses yet

Write a response