• 1.
    class Walker_Nav_Menu_Dropdown extends Walker_Nav_Menu {
  • 2.
        function start_lvl($output, $depth) {
  • 3.
            $indent = str_repeat("\t", $depth); // don't output children opening tag (`<ul>`)
  • 4.
        }
  • 5.
     
  • 6.
        function end_lvl($output, $depth) {
  • 7.
            $indent = str_repeat("\t", $depth); // don't output children closing tag
  • 8.
        }
  • 9.
     
  • 10.
        function start_el($output, $item, $depth, $args) {
  • 11.
            // add spacing to the title based on the depth
  • 12.
            $item->title = str_repeat("&nbsp;", $depth * 4).$item->title;
  • 13.
     
  • 14.
            parent::start_el($output, $item, $depth, $args);
  • 15.
     
  • 16.
            // no point redefining this method too, we just replace the li tag...
  • 17.
            $output = str_replace('<li', '<option value="' . $item->url . '"', $output);
  • 18.
        }
  • 19.
     
  • 20.
        function end_el($output, $item, $depth) {
  • 21.
            $output .= "</option>\n"; // replace closing </li> with the option tag
  • 22.
        }
  • 23.
    }
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 value="' . $item->url . '"', $output); } function end_el($output, $item, $depth) { $output .= "</option>\n"; // replace closing </li> with the option tag } }

Copy Code to Clipboard Raw

Sign-in or Create a Free Account.

Snippi uses Twitter or Facebook to register and create accounts. Registration will enable you to keep track of your snippets. We never spam your timeline or wall. Ever.

Sign-in with Facebook Sign-in with Twitter