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'm using the following walker to create a dropdown menu that I will use on a mobile version of a project I'm working on... it works fine, however, when I select the page, it doesn't load the page, what am I missing?

class Walker_Nav_Menu_Dropdown extends Walker_Nav_Menu{
    function start_lvl(&$output, $depth){
      $indent = str_repeat("\t", $depth); // don't output children opening tag (`<ul>`)

    function end_lvl(&$output, $depth){
      $indent = str_repeat("\t", $depth); // don't output children closing tag

    function start_el(&$output, $item, $depth, $args){
      // add spacing to the title based on the depth
      $item->title = str_repeat("&nbsp;", $depth * 4).$item->title;

      parent::start_el(&$output, $item, $depth, $args);

      // no point redefining this method too, we just replace the li tag...
      $output = str_replace('<li', '<option', $output);

    function end_el(&$output, $item, $depth){
      $output .= "</option>\n"; // replace closing </li> with the option tag

Thanks in advance.

share|improve this question
up vote 1 down vote accepted

You have to tell the browser to change the address in some way.

A simple javascript solution is to put the item URL into the value attribute, and trigger the address change when the option is selected.


$output = str_replace('<li', '<option', $output);


$output = str_replace(
 '<option value="'.$item->url.'" onchange="window.location.href=this.value"',

share|improve this answer
And don't forget a submit button for users without JavaScript. – toscho Apr 9 '12 at 21:53
thanks a ton! worked like charm – andresmijares25 Apr 10 '12 at 16:22
I just realized that I did not make it work exactly as you said, just in case anyone else needs 1, the onchange event has to be placed it in the select, not the option! everything else is perfect – andresmijares25 Apr 13 '12 at 18:40

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.