Last active
August 29, 2015 14:06
-
-
Save srikat/d16b2135c9cd6bba1f93 to your computer and use it in GitHub Desktop.
How to display Custom Menu as Select Dropdown in WordPress. http://sridharkatakam.com/display-custom-menu-select-dropdown-wordpress/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//* Do NOT include the opening php tag | |
// [menudropdown menu="Header Menu"] | |
function menu_as_dropdown( $atts ) { | |
// Attributes | |
extract( shortcode_atts( | |
array( | |
'menu' => 'Select Menu', | |
), $atts ) | |
); | |
ob_start(); | |
wp_nav_menu( array( | |
// 'theme_location' => 'mobile', | |
'menu' => $menu, | |
'walker' => new Walker_Nav_Menu_Dropdown(), | |
'items_wrap' => '<div class="mobile-menu"><form><select onchange="if (this.value) window.location.href=this.value">%3$s</select></form></div>', | |
) ); | |
return ob_get_clean(); | |
} | |
add_shortcode( 'menudropdown', 'menu_as_dropdown' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//* Do NOT include the opening php tag | |
// Nav Menu Dropdown Class | |
include_once( CHILD_DIR . '/lib/classes/nav-menu-dropdown.php' ); | |
wp_nav_menu( array( | |
// 'theme_location' => 'mobile', | |
'menu' => 'Header Menu', | |
'walker' => new Walker_Nav_Menu_Dropdown(), | |
'items_wrap' => '<div class="mobile-menu"><form><select onchange="if (this.value) window.location.href=this.value">%3$s</select></form></div>', | |
) ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//* Do NOT include the opening php tag | |
// Nav Menu Dropdown Class | |
include_once( CHILD_DIR . '/lib/classes/nav-menu-dropdown.php' ); | |
/** | |
* Mobile Menu | |
* | |
*/ | |
function be_mobile_menu() { | |
wp_nav_menu( array( | |
// 'theme_location' => 'mobile', | |
'menu' => 'Header Menu', | |
'walker' => new Walker_Nav_Menu_Dropdown(), | |
'items_wrap' => '<div class="mobile-menu"><form><select onchange="if (this.value) window.location.href=this.value">%3$s</select></form></div>', | |
) ); | |
} | |
add_action( 'genesis_before_header', 'be_mobile_menu' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[menudropdown menu="Header Menu"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.mobile-menu { | |
max-width: 400px; | |
margin: 40px auto; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment