Snippi
A super awesome snippet tool.
- 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(" ", $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.
}