Skip to content

Instantly share code, notes, and snippets.

@prionkor
Last active August 29, 2015 13:57
Show Gist options
  • Save prionkor/9671803 to your computer and use it in GitHub Desktop.
Save prionkor/9671803 to your computer and use it in GitHub Desktop.
<?php
/*
* Walker Class for Output Select Element from WordPress Menus
*
* */
class WPK_Select_Walker extends Walker_Nav_Menu {
// add main/sub classes to li's and links
function start_el( &$output, $item, $depth, $args ) {
$label = ! empty( $item->title ) ? esc_attr( $item->title ) : '';
// build html
$output .= '<option value="'.esc_attr($item->url).'">'.$label;
}
function end_el( &$output, $item, $depth, $args ) {
$output .= '</opiton>';
}
}
/*
Example:
$args = array(
'theme_location' => 'my_location',
'menu' => '',
'container' => false,
'fallback_cb' => false,
'items_wrap' => '<select id="%1$s" class="%2$s">%3$s</select>', // Important
'depth' => 1,
'walker' => new WPK_Select_Walker()
);
wp_nav_menu($args);
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment