How to Include & Indent Subcategories Using wp_dropdown_categories

Title of blog post with landscape background

I was using wp_dropdown_categories() this week to, well… Create a dropdown menu that links users to the category archives page on a WordPress website, obviously. And I couldn’t figure out how to indent the subcategories, even though that seemed like a very obvious thing you’d want to do.

Google was amazingly useless in this task. Though it almost always is, unless what you are searching for is top 10 list that has almost nothing to do with your query.

Anyway, it’s super easy. The solution:

All you have to do is set the parameter hierarchical to true . That’s it!
The WordPress Codex page for this function describes the parameter as such:

Whether to traverse the taxonomy hierarchy. Accepts 0, 1, or their bool equivalents. Default 0.

While you might think that this would simply hide or display the subcategories, it has the bonus of also indenting them built-in. Or at least it did with themes I’ve tried it with.

It did not require any additional tweaking from me: it just worked!

Pretty easy stuff.

Screenshot of a dropdown menu with subcategories indented

Just as an example, here is how I defined my parameters, including this one:

Normally nothing is this easy, but this time it was.

About Brian Johnson

Brian Johnson

Brian Johnson is the founder of PageCrafter, a Minneapolis-area web design and hosting company. He specializes in WordPress development, website security, hosting infrastructure, and ongoing website maintenance. Brian works hands-on with hundreds of business websites, helping organizations keep their WordPress sites secure, reliable, and up to date and has been building websites for almost two decades.

Leave a Reply

Your email address will not be published. Required fields are marked *