Display Subcategories on Category Pages in WordPress

Sep 29th, 2015Comments Off on Display Subcategories on Category Pages in WordPress

So basically this hack is allowing you to List subcategories if viewing a Category, and brothers / sibling categories if in subcategory.

    if (is_category()) {
    $this_category = get_category($cat);
    $this_category = wp_list_categories('orderby=id&show_count=0
    "&echo=0"); else
    $this_category = wp_list_categories('orderby=id&depth=1&show_count=0
    if ($this_category) { ?> 

<?php echo $this_category; ?>


<?php } ?>


Paste the above code wherever you like the categories to display and modify it however you please. The code listed above, when you visit the subcategory from the main category, hides the main category and only shows the subcategories.

If you want to show the main category also on subcategory pages, just remove the parameter depth=”1″ from the code above.

Don’t forget that you’ve seen this first at SEO expert Paul Hoda’s Blog.