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 is a website developer and designer living in Minneapolis, Minnesota with a passion for code and WordPress. He spends his days building WordPress websites for small businesses, developing new code with the online community, and living life.

Leave a Reply

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