WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have set up a wp_nav_menu in Wordpress. I have 2 parent categories, with 2 sub-categories each, so this produces a nested list.

My current code to call this menu is...

<?php wp_nav_menu( 
            'theme_location'    =>  'shop-categories',
            'container'         =>  'nav',
            'container_class'   =>  'shop-cat'
    ); ?>

... which outputs this...

(I have simplified the code so you just get an idea of the markup)

<nav class="shop-cat">

Now I would like to output this...

  <optgroup label="Clothing">
    <option value="T-Shirts">T-Shirts</option>
    <option value="Tops">Tops</option>
  <optgroup label="Accessories">
    <option value="Earings">Earings</option>
    <option value="Hats">Hats</option>

...is this possible to do dynamically? Or will it be better to do this manually? I have had a look around but couldn't find any help on this.

Any help appreciated.

share|improve this question
up vote 1 down vote accepted

Have you checked wp_dropdown_categories function?

It displays or retrieves the HTML dropdown list of categories. I'm unsure of your exact needs but it could be a good starting point.

share|improve this answer
Yes that is what I want to do. Just display the categories in a Select menu. I will give this a go then report back, it does seem like a good answer – Adam May 21 '13 at 9:26
Thanks mate, that is what I was after – Adam May 21 '13 at 20:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.