Grow your CSS skills. Land your dream job.

Wrap wp_nav_menu output around option tags for select menu

  • # May 20, 2013 at 5:29 pm

    Hi all

    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(
    array(
    ‘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)

    Now I would like to output this…

    …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.

    # May 20, 2013 at 5:35 pm

    You will need to extend Walker Class for wp_nav_menu(): http://wordpress.stackexchange.com/questions/14037/menu-items-description-custom-walker-for-wp-nav-menu

    # May 20, 2013 at 6:09 pm

    Thanks for pointing me in the right direction.

    Looking at that code…pretty complex for a PHP novice!

    I may consider a manual solution as I can see the optgroup labels being a problem.

    # May 21, 2013 at 11:55 am

    Is there a particular reason you’re wanting to spit out a form using the custom menu system?

    What’s the functionality you’re looking for here ?

    # May 21, 2013 at 4:02 pm

    Sorry I was using the wrong function.

    wp_dropdown_categories was the function I was looking for which does this by default.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".