Skip to content

Instantly share code, notes, and snippets.

@robincornett
Created July 13, 2014 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save robincornett/266a702b85e60daaedf7 to your computer and use it in GitHub Desktop.
Save robincornett/266a702b85e60daaedf7 to your computer and use it in GitHub Desktop.
updated Walker_Nav_Menu_Dropdown class for strict standards
<?php
/**
* source: http://www.billerickson.net/code/wordpress-menu-as-select-dropdown/
* Use this class to set up a nav menu to use as a dropdown menu.
*/
class Walker_Nav_Menu_Dropdown extends Walker_Nav_Menu{
function start_lvl( &$output, $depth = 0, $args = array() ){
$indent = str_repeat("\t", $depth); // don't output children opening tag (`<ul>`)
}
function end_lvl( &$output, $depth = 0, $args = array() ){
$indent = str_repeat("\t", $depth); // don't output children closing tag
}
/**
* Start the element output.
*
* @param string $output Passed by reference. Used to append additional content.
* @param object $item Menu item data object.
* @param int $depth Depth of menu item. May be used for padding.
* @param array $args Additional strings.
* @return void
*/
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
$url = '#' !== $item->url ? $item->url : '';
$output .= '<option value="' . $url . '">' . $item->title;
}
function end_el( &$output, $item, $depth = 0, $args = array() ){
$output .= "</option>\n"; // replace closing </li> with the option tag
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment