Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

How to Hide or Style Your Subcategories in WordPress

Would you like to hide subcategories in WordPress, or style them so that your category list is easier to read?

In WordPress, your posts can be organized into different categories and subcategories, which helps with navigation and SEO. However, in our experience, a long list of subcategories doesn’t always look good on your site.

In this tutorial, we will show you how you can hide the subcategories and change their style using a code snippet.

How to Hide or Style Your Subcategories in WordPress

Why Use Subcategories in WordPress?

When you write posts for your WordPress site, you can organize them using categories and tags. When you categorize content properly you can boost your SEO, which will bring more traffic to your site.

Organizing your posts will also improve your site’s navigation so visitors can find the content they are looking for more easily. You can even create subcategories when the structure of your site becomes more complex.

For example, a travel blog could have a category for sightseeing destinations in the United States. As its content grows, it may make sense to create subcategories for cities like Chicago, Los Angeles and New York City.

If you display your categories in a WordPress widget, then you can use a flat list or a hierarchy. Here’s how each option looks on our demonstration site.

Subcategories Can Be Displayed in a Hierarchical List

You do this by visiting Appearance » Widgets on your WordPress dashboard and checking the ‘Show hierarchy’ box on your Categories widget.

Show hierarchy in the Categories Widget

But whichever option you choose, the list will eventually become long and unmanageable, and won’t look good on your WordPress site.

In this guide, we’ll show you how to hide subcategories to make your category list is easier to navigate and show you how to style the subcategories for a cleaner look. You can use the quick links below to jump to the section you’re most interested in:

How to Hide Your Subcategories in WordPress Using CSS

In this article, we’ll be using CSS code snippets to hide and style your subcategories. You can add the snippets directly to your theme’s style.css file, to a code snippets plugin like WPCode, or add them using the Theme Customizer in your WordPress dashboard.

Adding CSS can be tricky for beginners, and making a mistake could break your WordPress site. If you’re new to using code snippets, then you might like to check our guide on how to easily add custom CSS to your WordPress site.

With that being said, let’s look at how to hide subcategories in WordPress.

You’ll need to copy the following code and paste it into your theme’s style.css file, your code snippets plugin, or your WordPress Theme Customizer.

.children {
display:none;
}

To use the Theme Customizer, you first need to navigate to Appearance » Customize and then click on ‘Additional CSS’ at the bottom of the list. After that, you simply paste in the code and then click on the ‘Publish’ button.

Using the Theme Customizer to Hide Subcategories

You can now visit your WordPress site to make sure the subcategories are hidden. Here are before and after screenshots from our test website.

Preview of Hidden Subcategories

That looks much cleaner, but now your visitors can’t see the subcategories. You might like to check our guide on how to display subcategories on your WordPress category pages.

If you do that, then when your visitors click on the United States category they will see links on that page to the subcategories, such as Chicago, Los Angeles and New York City.

How to Style Your Subcategories in WordPress Using CSS

You can also use CSS to customize the way your categories and subcategories look. This will depend on your own knowledge of CSS and what you’d like to change about the way they look in your current theme.

For example, if you display your subcategories in a hierarchy, then adding vertical bars will let you quickly see which categories are on the same level. Let’s have a look at how to do that.

Changing the style of your subcategories follows the same procedure as hiding them. You need to copy the code below and paste it into style.css, the WPCode plugin, or the WordPress Theme Customizer.

.children {
padding: 0 0 0 5px;
margin: 0 0 0 2px;
border-left: 1px solid #333;
}

If you use the Theme Customizer, then don’t forget to click the ‘Publish’ button.

Once you’ve done that you can visit your WordPress site to preview the changes. Here are before and after screenshots from our test website.

Preview of Styling Subcategories

Feel free to make adjustments to the code to customize the style to your taste.

You can also use CSS to style other elements of your WordPress theme. For example, you can use CSS to style individual categories differently.

Expert Guides on Categories and Subcategories in WordPress

Now that you know how to hide or style your subcategories, you might want to see some other tutorials on using categories and subcategories in WordPress:

We hope this tutorial helped you learn how to hide your subcategories in WordPress as well as change their style. You may also want to check out our list of must-have WordPress plugins to grow your site or our tutorial on how to display related posts in WordPress.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

4 CommentsLeave a Reply

  1. Farukh Hussain

    Wow, Thanks for this easy tip. You r a lifesaver like always. God bless.

    • WPBeginner Support

      You’re welcome, glad our guide was helpful :)

      Admin

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.