Skip to content
BeoHosting
BeoHosting
WordPress

Guide to WordPress Taxonomies

BeoHosting Team··10 min read read
Guide to WordPress Taxonomies

What are WordPress taxonomies

A taxonomy is a system for classifying and organizing content into groups. In everyday life we use taxonomies all the time - books in a library are organized by genre, products in a store are assigned categories, and animals are classified by species, genus, and family. The WordPress content system uses taxonomies the same way to organize posts, pages, and custom post types into logical groups that make visitor navigation and content search easier.

WordPress by default comes with two built-in taxonomies for posts - categories and tags. Categories are hierarchical meaning they can have parent and child categories while tags are flat without hierarchy. Besides these, there are also hidden taxonomies like link categories and post formats. WordPress also lets you create completely custom taxonomies for organizing any type of content in a way that fits your specific needs.

Categories - hierarchical taxonomy

How categories work

Categories are the primary taxonomy for organizing blog posts. Every post must belong to at least one category, and if you don't assign a category WordPress automatically assigns the Uncategorized category. Categories are hierarchical meaning you can create subcategories. For example, the Technology category can have subcategories Hardware, Software, and Mobile Devices. The Software subcategory can further have subcategories Operating Systems and Applications. This hierarchy helps organize large amounts of content.

Best practices for categories

Plan the category structure before you start writing content. The ideal number of categories for a blog is 5 to 10 because too many categories confuse visitors and dilute SEO strength. Every category should have enough posts to justify its existence - a category with one post isn't useful. Use descriptive names that clearly communicate what visitors can expect in that category. The category slug should be short and contain keywords relevant for SEO.

Add a description to every category because it displays on the category archive page and is used for the meta description in SEO. Set a featured image for categories using a plugin like Category Images to have a visual identity for every category. Avoid adding a post to too many categories - ideally one post in one category. If a post belongs in multiple categories, that's a sign your category system needs restructuring.

Tags - flat taxonomy

Difference between tags and categories

Tags are a flat taxonomy without hierarchy meaning they can't have parents and children. While categories define broad thematic groups, tags describe specific content details. For example, a post in the Recipes category can have tags like vegetarian, quick meal, gluten-free, and Mediterranean cuisine. Tags are optional unlike categories and one post can have multiple tags. Picture categories as chapters in a book and tags as the index of terms at the end.

Efficient tag use

Use tags consistently across the entire site. If you use the tag WordPress once and WordPress blog another time, you have two separate tags instead of one. Limit the number of tags per post to 5 to 10 because too many tags dilute their usefulness. Don't use tags that are the same as categories because that creates duplicate content. A tag should be used on at least 3 posts to be useful, and tags with only one post should be deleted or consolidated. Regularly review and clean unused tags using the Tools then Tax Meta plugin or manually through the admin panel.

Custom taxonomies

When to create a custom taxonomy

Custom taxonomies are needed when default categories and tags can't adequately organize your content. For example, a real estate site needs taxonomies for property type (apartment, house, commercial space), location (New York, Los Angeles, Chicago), and price range. An online store can have taxonomies for brand, material, size, and color. A movie blog can have taxonomies for genre, director, year, and rating. Each of these examples requires its own taxonomy because mixing them all in one category would be impractical.

Registering a custom taxonomy

A custom taxonomy is created with the register_taxonomy function called inside the init hook. The function takes three arguments - the taxonomy slug which is the internal identifier, an array of post types the taxonomy applies to, and an array of arguments that define behavior. The slug should be singular, lowercase, with no spaces, and up to 32 characters. Key arguments include labels defining names in the admin panel, hierarchical determining whether the taxonomy is hierarchical or flat, show_in_rest for Gutenberg support, and rewrite for URL structure.

Code example

To register a project type taxonomy for the project custom post type, you create a function that calls register_taxonomy with the first argument project_type, the second argument an array containing project, and the third argument an array with labels, hierarchical set to true for a checkbox interface or false for a tag interface, show_in_rest to true, rewrite with slug project-type, and show_admin_column to true so the column displays in the post list in the admin panel. Hook this function to init with add_action.

Hierarchical vs flat taxonomies

Hierarchical taxonomies

Hierarchical taxonomies work like categories with the ability to create parent-child relationships. In the admin panel they display as a checkbox list with indentation for subcategories. Use hierarchical taxonomies when your classification has a clear level structure. For example, location can have a structure the US then California then Los Angeles or Music genre then Rock then Alternative Rock then Indie Rock. The hierarchy helps with navigation because visitors can choose a broad category and then narrow the choice.

Flat taxonomies

Flat taxonomies work like tags without the ability to have a hierarchy. In the admin panel they display as a tag input field where you type terms separated by commas. Use flat taxonomies for flexible labels that don't have a natural hierarchy. For example, skills (PHP, JavaScript, WordPress), product features (waterproof, wireless, portable), or recipe ingredients. Flat taxonomies are easier to maintain because they don't require planning a structure and users can freely add new terms.

Choosing taxonomy type

Questions that help with the decision include whether the classification has natural levels like country, city, neighborhood. If yes, use hierarchical. Whether users should choose from a predefined list or freely add new terms. If the list is fixed, hierarchical is better because the administrator controls the structure. Whether the number of terms is small and stable or large and growing. A small stable number favors hierarchical while a large growing number favors flat. Whether a term can belong to another term. If there's a logical parent-child relationship, use hierarchical.

Template files for taxonomies

WordPress template hierarchy

WordPress uses a specific hierarchy to determine which template file displays a taxonomy. For categories, WordPress looks for category-slug.php then category-id.php then category.php then archive.php then index.php. For tags it looks for tag-slug.php then tag-id.php then tag.php then archive.php. For custom taxonomies it looks for taxonomy-slug-term.php then taxonomy-slug.php then taxonomy.php then archive.php. By creating a specific template file you have full control over the taxonomy display.

Custom taxonomy template

The template file for a taxonomy typically contains the taxonomy title fetched with single_term_title, the taxonomy description with term_description, a list of subcategories if it's a hierarchical taxonomy, and a loop that displays posts in that taxonomy. For visually appealing display, use a grid layout with thumbnails, titles, and short post descriptions. Add a sidebar with a list of all terms in the taxonomy for easier navigation and pagination at the bottom for a large number of posts.

Displaying taxonomies in templates

WordPress provides several functions for working with taxonomies in templates. The get_the_terms function returns all terms of a specific taxonomy for a given post. The the_terms function displays links to terms with a configured separator. The get_terms function fetches all taxonomy terms independent of the post which is useful for sidebar widgets and filters. The wp_list_categories function with the taxonomy argument displays a hierarchical list of terms. For advanced queries, use the WP_Term_Query class with arguments for filtering, sorting, and limiting results.

Advanced techniques

Taxonomy meta fields

Since WordPress 4.4, taxonomy terms can have meta data similar to posts. This allows adding custom fields to categories and tags like category color, icon, featured image, or any other data. Use add_term_meta, get_term_meta, and update_term_meta functions for working with meta data. For the user interface in the admin panel, hook to the edit_category_form_fields and create_category hooks to add input fields. The ACF plugin significantly simplifies this process because it allows adding fields to categories through a visual interface without coding.

REST API and taxonomies

With the show_in_rest argument set to true, a custom taxonomy automatically gets a REST API endpoint. This enables fetching terms via JavaScript for dynamic content filtering without reloading the page, creating terms from frontend forms, integration with external applications, and use in the Gutenberg editor. The REST API endpoint for a taxonomy is at /wp-json/wp/v2/taxonomy-slug with support for pagination, search, filtering by parent term, and sorting.

Conclusion

WordPress taxonomies are a powerful system for content organization that goes beyond simple categories and tags. Understanding the difference between hierarchical and flat taxonomies, knowing when to create a custom taxonomy, and the ability to customize templates for displaying taxonomies are key skills for advanced WordPress development. Well-organized content not only improves user experience but directly affects SEO because Google values clear site structure. Learn more in the WordPress SEO guide. On our optimized WP hosting we provide optimal performance for sites with complex taxonomy structures and a large number of posts.

BeoHosting Team

10+ years of experience — Web hosting and infrastructure specialists

  • Web Hosting
  • WordPress Hosting
  • VPS
  • Dedicated Serveri
  • Domeni
  • SSL
  • cPanel
  • LiteSpeed
  • Linux administracija
  • DNS

Last updated: