How to Add Categories and Subcategories in WordPress (2023)
Categories and subcategories provide a powerful way to organize and structure content on your WordPress site. When used strategically, they can enhance your site‘s usability, SEO, and overall effectiveness at reaching your audience and goals.
In this guide, we‘ll walk through everything you need to know to make the most of categories and subcategories in WordPress. You‘ll learn how to create them, how to display them, and most importantly, how to plan and use them for maximum impact. Let‘s dive in!
Understanding Categories, Subcategories, and Tags
Before we get into the technical how-to, it‘s important to clarify exactly what categories and subcategories are and how they differ from tags:
- Categories are meant for broad grouping of post topics. If your website was a book, categories would be like the chapters.
- Subcategories (or "child categories") are nested under a parent category to further organize related subtopics. To continue the book analogy, subcategories are like sections within a chapter.
- Tags are meant to describe specific details of a post. Think of them as the index words at the back of a book.
Here are a few examples of how you might organize a site with categories and subcategories:
- A recipe site might have parent categories for Breakfast, Lunch, Dinner, and Desserts, with subcategories like Pancakes, Sandwiches, Pasta, and Cookies.
- An automotive site could have top-level categories for Repairs, Reviews, and News, with subcategories for various makes/models, comparisons, or local events.
- A fitness blog may categorize by types of Exercise, Health Topics, and Nutrition, breaking those down further into subcategories like Yoga, Weight Loss, and Meal Planning.
The key is to choose categories and subcategories that make sense for your unique content and target audience. They should create an intuitive structure so visitors can easily browse and find information on your site.
Why Use Categories and Subcategories?
Now that you understand what categories and subcategories are, let‘s look at some of the key benefits of using them on your WordPress site:
Improved User Experience
Well-planned categories and subcategories make your site easier to navigate and use. Visitors can quickly drill down to the most relevant content and avoid wasting time sifting through irrelevant posts. This improved usability can lead to longer visits, more engagement, and higher conversions.
Better SEO
Organizing content with categories tells search engines what your site is about. This helps your rankings for relevant topics and keywords. You can even optimize your category pages themselves by adding descriptions that include target keywords.
Categories also create an SEO-friendly URL structure (more on that later) and help funnel authority to important pages. All of this adds up to stronger SEO and more organic search traffic.
Related Posts & Content Recommendations
Many WordPress themes and plugins use categories to dynamically display related content. This could be a "Related Posts" section after a blog post or content recommendations in a sidebar. These features keep visitors engaged and viewing more pages.
With subcategories, you can fine-tune these recommendations and cross-promote highly relevant posts. This automation saves time while providing a better, more personalized user experience.
Easier Social Media Promotion
Categories can speed up your social media workflow by allowing you to quickly grab a link to a category page. This is helpful for sharing a collection of related content or providing a convenient way for followers to browse a certain topic on your site. It‘s much faster than hunting down individual post links.
How to Create Categories in WordPress
Ready to start organizing your WordPress site with categories and subcategories? Follow these step-by-step instructions.
Option 1: Create Categories from the Posts > Categories Screen
- In your WordPress dashboard, go to Posts > Categories.
- Enter a Name for your new category.
- Choose a Parent category if you want this to be a subcategory, or leave it blank for a top-level category.
- Enter a Slug if you want it to be different than the Name. The slug is what shows in the category URL.
- Add a Description for your category. This isn‘t required, but it can be helpful for SEO.
- Click the Add New Category button.
Option 2: Create Categories While Writing a Post
- Open the post editor for a new or existing post.
- In the Document panel on the right, open the Categories section.
- Click Add New Category.
- Enter a Name for your category.
- Choose a Parent category from the dropdown if this will be a subcategory.
- Click Add New Category.
- The new category will be automatically applied to the post. You can uncheck it if you don‘t want it applied to that particular post.
Using option 1 is better if you want to set up all your categories before you start creating content. Option 2 is convenient for adding new categories on the fly while writing.
How to Create Subcategories in WordPress
Creating subcategories follows the exact same steps as creating main categories. The only difference is choosing a Parent category from the dropdown.
Simply complete the Name field and choose the appropriate Parent category that the subcategory should be nested under. You can even create multiple levels of parent > child > grandchild categories by nesting subcategories under other subcategories.
Keep in mind that a subcategory can only have one immediate parent category. This creates a logical hierarchy and site structure.
Customizing Category URLs
By default, WordPress category pages have a URL structure like this:
https://yoursite.com/category/category-name/
However, you can customize the way these URLs appear in two ways:
Change the "category base" (the /category/ part) in Settings > Permalinks. For example, you could change it to /topics/ so the URL would be
https://yoursite.com/topics/category-name/Remove the category base entirely so the URL is just
https://yoursite.com/category-name/. This is a popular option for cleaning up category URLs and making them more SEO-friendly. To do this, you can use a plugin like Remove Category URL or add this code snippet to your theme‘s functions.php file or a plugin like Code Snippets:
// Remove Category Base
add_action(‘init‘, ‘remove_category_base‘);
function remove_category_base() {
// Remove category base
add_action(‘created_category‘, ‘remove_category_base_refresh_rules‘);
add_action(‘edited_category‘, ‘remove_category_base_refresh_rules‘);
add_action(‘delete_category‘, ‘remove_category_base_refresh_rules‘);
// Remove product category base
add_action(‘created_product_cat‘, ‘remove_category_base_refresh_rules‘);
add_action(‘edited_product_cat‘, ‘remove_category_base_refresh_rules‘);
add_action(‘delete_product_cat‘, ‘remove_category_base_refresh_rules‘);
function remove_category_base_refresh_rules() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
register_deactivation_hook(__FILE__, ‘remove_category_base_deactivate‘);
function remove_category_base_deactivate() {
remove_action(‘created_category‘, ‘remove_category_base_refresh_rules‘);
remove_action(‘edited_category‘, ‘remove_category_base_refresh_rules‘);
remove_action(‘delete_category‘, ‘remove_category_base_refresh_rules‘);
remove_action(‘created_product_cat‘, ‘remove_category_base_refresh_rules‘);
remove_action(‘edited_product_cat‘, ‘remove_category_base_refresh_rules‘);
remove_action(‘delete_product_cat‘, ‘remove_category_base_refresh_rules‘);
}
}
// Rewrite rules
add_filter(‘category_rewrite_rules‘, ‘remove_category_base_rewrite_rules‘);
function remove_category_base_rewrite_rules($category_rewrite) {
$category_rewrite = array();
$categories = get_categories(array(‘hide_empty‘ => false));
foreach ($categories as $category) {
$category_nicename = $category->slug;
if ($category->parent == $category->cat_ID)
$category->parent = 0;
elseif ($category->parent != 0)
$category_nicename = get_category_parents($category->parent, false, ‘/‘, true) . $category_nicename;
$category_rewrite[‘(‘ . $category_nicename . ‘)/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$‘] = ‘index.php?category_name=$matches[1]&feed=$matches[2]‘;
$category_rewrite[‘(‘ . $category_nicename . ‘)/page/?([0-9]{1,})/?$‘] = ‘index.php?category_name=$matches[1]&paged=$matches[2]‘;
$category_rewrite[‘(‘ . $category_nicename . ‘)/?$‘] = ‘index.php?category_name=$matches[1]‘;
}
global $wp_rewrite;
$old_category_base = get_option(‘category_base‘) ? get_option(‘category_base‘) : ‘category‘;
$old_category_base = trim($old_category_base, ‘/‘);
$category_rewrite[$old_category_base . ‘/(.*)$‘] = ‘index.php?category_redirect=$matches[1]‘;
return $category_rewrite;
}
add_filter(‘query_vars‘, ‘remove_category_base_query_vars‘);
function remove_category_base_query_vars($public_query_vars) {
$public_query_vars[] = ‘category_redirect‘;
return $public_query_vars;
}
add_filter(‘request‘, ‘remove_category_base_request‘);
function remove_category_base_request($query_vars) {
if (isset($query_vars[‘category_redirect‘])) {
$catlink = trailingslashit(get_option(‘home‘)) . user_trailingslashit($query_vars[‘category_redirect‘], ‘category‘);
status_header(301);
header("Location: $catlink");
exit();
}
return $query_vars;
}If you decide to change your category URL structure on an existing site, make sure to set up 301 redirects from the old URLs to the new ones. This will prevent broken links and maintain your SEO.
Displaying Categories in WordPress
There are a few different ways you can display your categories on your WordPress site:
In a Sidebar Widget
One of the most common places to show a list of categories is in a sidebar. Here‘s how:
- Go to Appearance > Widgets in your WordPress dashboard.
- Find the Categories widget and drag it into your desired sidebar area.
- Customize the options, such as the title, display format (list or dropdown), and whether to show post counts.
- If you want subcategories to appear nested under their parents, check the "Show hierarchy" box.
- Click Save.
Now your categories and subcategories will appear in a tidy list or dropdown in the sidebar across your site. This makes it easy for visitors to browse content by topic.
You can also add important categories to your site‘s main navigation menu. Here‘s how:
- Go to Appearance > Menus.
- Select the menu you want to edit or create a new menu.
- Under Add menu items, select Categories.
- Check the categories you want to add and click Add to Menu.
- Arrange the menu items in the desired order by dragging and dropping. You can create a submenu by dragging a category slightly to the right under a parent item.
- Click Save Menu.
Your selected categories will now appear in your navigation menu, helping visitors quickly access key topics right from the header of your site.
On Archives & Post Feeds
WordPress automatically generates archive pages for your categories and subcategories. These pages display a chronological feed of all posts filed under that category, with the most recent posts first.
You can access a category archive by adding /category-name/ to the end of your site URL (or whatever structure you chose in the category URL settings).
Many WordPress themes also display the assigned categories on individual post pages, either near the title or in the post meta section. This creates more internal links to your category archives.
Best Practices for Using Categories Effectively
To wrap up, here are a few tips for getting the most out of categories and subcategories on your WordPress site:
- Plan your categories and subcategories before adding content. A little organization up front will save you a lot of time and headaches down the road.
- Keep your categories focused and relevant to your niche. Resist the temptation to create a category for every little thing.
- Use clear, descriptive names for your categories and subcategories. Avoid clever names or insider jargon that visitors might not understand.
- Optimize your category pages with keyword-rich titles and descriptions. This can give an SEO boost to some of the most important pages on your site.
- Use categories and subcategories consistently. Make sure every post is assigned to at least one relevant category.
- Go deep with subcategories to create a logical structure and funnel visitors to the most relevant content. A "Goldilocks" structure of 3-4 levels usually works best for SEO and usability.
- Cross-link related categories and subcategories to help visitors discover more content and keep them on your site longer.
By following these tips and best practices, you can create a well-organized site that‘s a joy to use and primed for success with search engines. Categories and subcategories are a key part of WordPress — make sure you‘re using them to their full potential!
