How to Create a Custom Taxonomy in WordPress Without a Plugin

In WordPress, a Custom Taxonomy is a way to organize content by grouping similar items together. WordPress has built-in taxonomies like Categories and Tags, but custom taxonomies allow you to create your own, more specific types. Here’s how you can create custom taxonomies with and without a plugin:

1) Creating Custom Taxonomy Without a Plugin

To create a custom taxonomy manually, you’ll need to add code to your theme’s functions.php file or a site-specific plugin. Here’s a basic example of how to create a custom taxonomy:

  1. Open your functions.php file.
  2. Add the following code to create a custom taxonomy:
function create_custom_taxonomy() {
register_taxonomy(
'topics', // Taxonomy key, must be unique
'posts', // Object type: post, page, or your custom post type
array(
'labels' => array(
'name' => 'Topics',
'add_new_item' => 'Add New Topic',
'new_item_name' => "New Topic"
),
'show_ui' => true,
'show_tagcloud' => false,
'hierarchical' => true // True for categories-like, false for tags-like
)
);
}
add_action('init', 'create_custom_taxonomy');

This code sets up a hierarchical taxonomy (like categories) named “Topics” for posts. You can adjust the object type and parameters to fit your needs.

2)Creating Custom Taxonomy With a Plugin

Using a plugin is the easiest way to create and manage custom taxonomies without coding. A popular plugin for this purpose is Custom Post Type UI. Here’s how to use it:

  1. Install the Plugin:
    • Go to your WordPress admin panel.
    • Navigate to Plugins > Add New.
    • Search for Custom Post Type UI.
    • Click Install Now and then activate the plugin.
  2. Create a Custom Taxonomy:
    • In the WordPress admin, go to CPT UI > Add/Edit Taxonomies.
    • Fill in the required fields, such as Taxonomy Slug, Plural Label, and Singular Label.
    • Associate the taxonomy with one or more post types.
    • Configure additional settings as needed, such as whether it’s hierarchical.
    • Click on Add Taxonomy to save your new taxonomy.

Share on :

Social Share

Recent Post

© 2024 All rights reserved by Go1digital.com