How To Display sub-categories on category pages in WordPress

How To Display sub-categories on category pages in WordPress

By default, WordPress does not allow the addition of sub-categories to the category. This post will explain How To Display sub-categories on category pages in WordPress.

The sub-category is generally known as the child category, which comes under the parent category. For example, you have a main category named App Development. Then you divide this parent category by going more in-depth into groups such as Android App Development and iOS App Development.

Moreover, showing sub-categories help you increase the SEO rank of your website and deliver a good browsing experience for readers who can readily navigate to the different types of content.

Displaying sub-categories on category pages in WordPress

1.Using manual codes

If you like coding and don’t want to put an extra load on your website by plugins, you can use the following code.

Place the following code wherever you like to display the sub-categories.

<?php

    if (is_category()) {

    $this_category = get_category($cat);

    }

    ?>

    <?php

    if($this_category->category_parent)

    $this_category = wp_list_categories('orderby=id&show_count=0

    &title_li=&use_desc_for_title=1&child_of='.$this_category->category_parent.

    "&echo=0"); else

    $this_category = wp_list_categories('orderby=id&depth=1&show_count=0

    &title_li=&use_desc_for_title=1&child_of='.$this_category->cat_ID.

    "&echo=0");

    if ($this_category) { ?> 

 

<ul>

<?php echo $this_category; ?>

 

</ul>

 

<?php } ?>

This code will help you to display sub-categories.

2.Using plugins

In WordPress, Plugins are the key to everything. You can use the given plugin for displaying the sub-categories in your WordPress site. For this, you have to Download the Sub-categories widget Plugin.

You can check our guide on how to install WordPress plugin to take help.

Sub Categories Widget

The sub-categories widget plugin will help you display the sub-categories on category pages when you divide your content into categories into sub-categories. You can add a list of sub-categories with the widget even if the parent doesn’t have posts.

Also, You can display and filter sub-categories in various ways. You can use the parent category as a widget title. There is an option to hide empty sub-categories. You can add a link to the parent category to the widget title. Furthermore, you can exclude one or more sub-categories from the list and many more.

To conclude, You can choose from the above whichever method suits you for showing the sub-categories on the category page on your WordPress website.

We hope this has helped you!

You can also check our other posts, how to hide or style subcategories in WordPress.

and how to hide /show categories in WordPress.

Leave a Comment