How to Create Custom Taxonomies in WordPress ⚠️

I’ve been working with WordPress for years and I recently discovered something that completely changed the way I think about organizing content. It’s all about custom taxonomies my friend.

Let me tell you it’s a must.

🔥 Want to unlock the full potential of your WordPress site and make it super organized and search-friendly? 🤯

Learn how to master custom taxonomies and boost your website game!

Diving Deep into WordPress Taxonomies: Beyond Categories and Tags




🔥 Want to unlock the full potential of your WordPress site and make it super organized and search-friendly? 🤯

Learn how to master custom taxonomies and boost your website game!

Imagine this: you’re building a website for a photography studio and you want to showcase your portfolio by genre like weddings portraits and landscapes.

Sure you can use categories for that but what if you also want to organize your photos by the specific camera lens used or the location of the shoot?

That’s where custom taxonomies come in! They allow you to create your own unique classification systems beyond the standard “Categories” and “Tags” that WordPress provides.

Why You Need Custom Taxonomies

You might be thinking “Why go through the hassle? Categories and tags are already there right?” Well here’s why custom taxonomies are a lifesaver:

  • Flexibility: They let you organize content in a way that perfectly suits your specific needs.
  • Enhanced Search: Visitors can easily filter and find the exact content they’re looking for by using your custom taxonomy terms.
  • Improved User Experience: A well-structured taxonomy system makes your website more user-friendly and enjoyable to navigate.
  • SEO Boost: By creating relevant taxonomies you can improve your website’s SEO by providing more structured data to search engines.

Creating Custom Taxonomies in WordPress

Now let’s get down to the nitty-gritty.

You can create custom taxonomies in WordPress through a couple of approaches: using a plugin or going the code route.

Plugin Power: The Easy Way

Plugins are a godsend for those who prefer a visual and user-friendly approach. One of my favorites is Pods known for its ease of use and comprehensive features. But hey there are plenty of other great options out there like Custom Post Type UI.

Let’s walk through the plugin method using Pods as our example:

  1. Install and Activate: First things first install and activate the Pods plugin from your WordPress dashboard.
  2. Create a New Taxonomy: Go to Pods Admin > Add New.
  3. Define Your Taxonomy: In the Content Type dropdown select “Custom Taxonomy.” Give your taxonomy a name (e.g. “Camera Lens”) and a plural name (e.g. “Camera Lenses”). You can even set up a hierarchical structure if needed like you would with categories.
  4. Configuration: Once you click “Next Step” you’ll be taken to a configuration screen where you can fine-tune your taxonomy. You can decide whether it’s hierarchical assign it to a specific post type and set up custom fields.
  5. Admin UI: Now head to the “Admin UI” tab and fill out the “Menu Name” field to give your taxonomy a recognizable label in your WordPress menu.
  6. Associate with Post Types: In the “Advanced Options” tab check the box next to the post types you want to associate your taxonomy with (e.g. “Posts”). This allows you to assign terms from your custom taxonomy to those post types.
  7. Save and Enjoy: Hit save and voila! Your new taxonomy is ready to use! It’ll appear alongside categories and tags in your post editing screen.

The Developer’s Touch: Using Code

For those who like to get their hands dirty with code you can create custom taxonomies with a few lines of code.

Here’s the breakdown:

  1. Hierarchical vs. Non-Hierarchical: First decide whether your taxonomy will be hierarchical (like categories) or non-hierarchical (like tags).
  2. Functions.php File: You’ll need to access your functions.php file which is located in your theme’s directory.
  3. Add Code Snippets: Add the following code snippets to your functions.php file choosing the appropriate one based on whether your taxonomy is hierarchical or not:

Hierarchical Taxonomy:

<?php
function register_my_taxonomy() {
    $labels = array(
        'name'                       => _x( 'Locations' 'Taxonomy General Name' 'textdomain' )
        'singular_name'              => _x( 'Location' 'Taxonomy Singular Name' 'textdomain' )
        'menu_name'                   => __( 'Locations' 'textdomain' )
        'all_items'                  => __( 'All Locations' 'textdomain' )
        'parent_item'                => __( 'Parent Location' 'textdomain' )
        'parent_item_colon'          => __( 'Parent Location:' 'textdomain' )
        'new_item_name'              => __( 'New Location Name' 'textdomain' )
        'add_new_item'              => __( 'Add New Location' 'textdomain' )
        'edit_item'                  => __( 'Edit Location' 'textdomain' )
        'update_item'                => __( 'Update Location' 'textdomain' )
        'view_item'                  => __( 'View Location' 'textdomain' )
        'separate_items_with_commas' => __( 'Separate locations with commas' 'textdomain' )
        'add_or_remove_items'        => __( 'Add or remove locations' 'textdomain' )
        'choose_from_most_used'      => __( 'Choose from the most used locations' 'textdomain' )
        'popular_items'              => __( 'Popular Locations' 'textdomain' )
        'search_items'               => __( 'Search Locations' 'textdomain' )
        'not_found'                  => __( 'Not Found' 'textdomain' )
        'no_terms'                   => __( 'No locations' 'textdomain' )
        'items_list'                 => __( 'Locations list' 'textdomain' )
        'items_list_navigation'      => __( 'Locations list navigation' 'textdomain' )
    );
    $args = array(
        'labels'            => $labels
        'hierarchical'      => true
        'public'            => true
        'show_ui'           => true
        'show_admin_column' => true
        'show_in_nav_menus' => true
        'show_tagcloud'     => true
        'rewrite'          => array( 'slug' => 'location' )
    );
    register_taxonomy( 'location' array( 'post' ) $args );
}
add_action( 'init' 'register_my_taxonomy' 0 );
?>

Non-Hierarchical Taxonomy:

<?php
function register_my_taxonomy() {
    $labels = array(
        'name'                       => _x( 'Camera Lenses' 'Taxonomy General Name' 'textdomain' )
        'singular_name'              => _x( 'Camera Lens' 'Taxonomy Singular Name' 'textdomain' )
        'menu_name'                   => __( 'Camera Lenses' 'textdomain' )
        'all_items'                  => __( 'All Camera Lenses' 'textdomain' )
        'parent_item'                => __( 'Parent Camera Lens' 'textdomain' )
        'parent_item_colon'          => __( 'Parent Camera Lens:' 'textdomain' )
        'new_item_name'              => __( 'New Camera Lens Name' 'textdomain' )
        'add_new_item'              => __( 'Add New Camera Lens' 'textdomain' )
        'edit_item'                  => __( 'Edit Camera Lens' 'textdomain' )
        'update_item'                => __( 'Update Camera Lens' 'textdomain' )
        'view_item'                  => __( 'View Camera Lens' 'textdomain' )
        'separate_items_with_commas' => __( 'Separate camera lenses with commas' 'textdomain' )
        'add_or_remove_items'        => __( 'Add or remove camera lenses' 'textdomain' )
        'choose_from_most_used'      => __( 'Choose from the most used camera lenses' 'textdomain' )
        'popular_items'              => __( 'Popular Camera Lenses' 'textdomain' )
        'search_items'               => __( 'Search Camera Lenses' 'textdomain' )
        'not_found'                  => __( 'Not Found' 'textdomain' )
        'no_terms'                   => __( 'No camera lenses' 'textdomain' )
        'items_list'                 => __( 'Camera Lenses list' 'textdomain' )
        'items_list_navigation'      => __( 'Camera Lenses list navigation' 'textdomain' )
    );
    $args = array(
        'labels'            => $labels
        'hierarchical'      => false
        'public'            => true
        'show_ui'           => true
        'show_admin_column' => true
        'show_in_nav_menus' => true
        'show_tagcloud'     => true
        'rewrite'          => array( 'slug' => 'camera-lens' )
    );
    register_taxonomy( 'camera-lens' array( 'post' ) $args );
}
add_action( 'init' 'register_my_taxonomy' 0 );
?>

Remember: Replace the placeholders with your desired taxonomy name and other configuration options. Also make sure to save your changes in functions.php.

Putting It All Together: Displaying Your Custom Taxonomies

You’ve created your custom taxonomies but now it’s time to show them off! You need to integrate them into your WordPress templates.

Here’s how:

  1. Template Hierarchy: Familiarize yourself with WordPress’s template hierarchy. This will help you determine which template file to edit for your custom taxonomy display.
  2. Template File Selection: Decide where you want your taxonomy to appear. You’ll likely modify files like single.php content.php or within your theme’s template-parts folder. If you’re unsure use the Which Template Am I plugin to find out which template a specific page is using.
  3. Add Code Snippet: In your selected template file find the spot where you want the taxonomy to display. Then add the following code snippet:
<?php the_terms( $post->ID 'camera-lens' 'Camera Lenses: ' ' ' ' ' ); ?>

Key Points:

  • Replace 'camera-lens' with the name of your custom taxonomy.
  • Customize the text before and after the terms (e.g. “Camera Lenses: “) to suit your needs.

That’s it! Once you save your changes your custom taxonomy will be displayed on your website.

Custom Taxonomies in WooCommerce

Need to organize your products in WooCommerce? You can use the same principles we’ve discussed!

Here’s how to create a custom taxonomy for WooCommerce products:

  1. Follow the Plugin Method: Use the plugin approach outlined above making sure to select “Products (product)” in the “Advanced Options” tab when associating your taxonomy with post types.
  2. Apply to WooCommerce: The rest of the process is the same and your new taxonomy will be ready to use with your WooCommerce products!

Mastering Custom Taxonomies: Leveling Up Your WordPress Game

By incorporating custom taxonomies into your WordPress strategy you can create a website that’s more organized search-friendly and visually appealing.

It’s a powerful tool that can take your website to the next level.

Remember:

  • Think about the specific needs of your website and choose taxonomy names and structures that will be both meaningful and user-friendly.
  • Use clear and concise language when defining your taxonomy terms.
  • Don’t hesitate to experiment with different approaches and see what works best for your specific content and audience.

So go forth and unleash the power of custom taxonomies! Your website will thank you for it.




🔥 Want to unlock the full potential of your WordPress site and make it super organized and search-friendly? 🤯

Learn how to master custom taxonomies and boost your website game!

Leave a Comment

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

Scroll to Top