Table of Contents Overview Ultimate Auction Pro Auctions Made Easy for WooCommerce Auctions for WooCommerce…
How to Display Child Categories Under Parent Categories in WordPress (Easy Guide)

Table of Contents
- What Are Parent and Child Categories in WordPress?
- Why Show Child Categories Under Parent Categories?
- Method 1: Use WordPress Default Menu Settings
- Method 2: Use a Plugin to Show Child Categories
- Method 3: Display Child Categories with Custom Code
- Style Child Categories with CSS (Optional)
- Final Tips and Best Practices
- FAQs
1. What Are Parent and Child Categories in WordPress?
WordPress categories help group your content. A parent category is the main category, and a child category is a sub-category under it.
Example:
- Parent: Recipes
- Child: Breakfast, Lunch, Dinner
This helps your site look more organized and makes it easier for visitors to find what they need.
2. Why Show Child Categories Under Parent Categories?
Showing child categories:
- Helps users browse related content
- Improves site navigation
- Boosts SEO by making internal linking clearer
- Looks professional and clean
3. Method 1: Use WordPress Default Menu Settings
- Go to your WordPress dashboard.
- Click on Appearance > Menus.
- Add parent and child categories to the menu.
- Drag child categories slightly to the right under the parent.
- Save the menu.
This creates a dropdown or nested list.
4. Method 2: Use a Plugin to Show Child Categories
You can use plugins like:
- Category and Taxonomy Tree
- WP Custom Category Pages
- Ultimate Category Excluder (for better control)
Steps:
- Install and activate a plugin of your choice.
- Go to its settings.
- Enable the option to show child categories.
- Customize the display as needed.
5. Method 3: Display All Parent Categories with Their Child Categories (Custom Code)
Add this PHP code to your theme’s functions.php
file or in a custom plugin:
$parent_categories = get_categories(array(
'parent' => 0,
'hide_empty' => false
));
echo '<ul>';
foreach ($parent_categories as $parent_cat) {
echo '<li><strong>' . esc_html($parent_cat->name) . '</strong>';
// Get child categories
$child_categories = get_categories(array(
'child_of' => $parent_cat->term_id,
'hide_empty' => false
));
if (!empty($child_categories)) {
echo '<ul>';
foreach ($child_categories as $child_cat) {
echo '<li>' . esc_html($child_cat->name) . '</li>';
}
echo '</ul>';
}
echo '</li>';
}
echo '</ul>';
This code will:
- Show their respective child categories nested underneath.
- List all top-level (parent) categories.
6. Style Child Categories with CSS (Optional)
To make the list look better, add CSS to your theme’s customizer:
.child-category-list {
margin-left: 20px;
font-style: italic;
}
7. Final Tips and Best Practices
- Always back up your site before editing code.
- Use a child theme to avoid losing changes after theme updates.
- Group categories logically.
- Avoid too many sub-levels to keep it simple.
8. FAQs
Can I display child categories in widgets?
Yes, you can use the Categories widget in Appearance > Widgets and check “Show hierarchy.”
Will this work with custom taxonomies?
Yes, but you’ll need to adjust the code or plugin settings to target your custom taxonomy.
What if child categories don’t show?
Make sure the categories are properly assigned and not empty. Use hide_empty => false
in code if needed.
Is it better to use a plugin or code?
Use a plugin for ease. Use code if you want full control and customization.
This Post Has 0 Comments