I’m using the following inside the wp_nav_menu
function to create a select dropdown menu where each menu item is an option in the select dropdown…
'items_wrap' => '<select>%3$s</select>'
'before' => '<option value="">'
'after' => '</option>'
How do I add the link value in the 'before'
declaration? Is there a better way to go about this? I know about wp_dropdown_pages
, but that doesn’t work because I want users to be able to control the menu from the “Menus” page.
You can’t do this with wp_nav_menu, because it outputs list items, and you’ll generate invalid markup with your code.
Try using wp_get_nav_menu_items() instead.
A quick solution for a drop down menu with a custom walker:
In your templates use it like this:
I have found that useful:
You can follow any responses to simplify css code dropdovn menu.
parent
for items that have a submenudepth
class (depth0 , depth1, depth2 …)add to function.php your theme
now in header.php
header-menu
replaced by the name of your menuCSS example code may be the
where
#menu-header-menu
– id the main UL list (you need to update that as well)Dropdown Menus plugin does answer the question:
wp_nav_menu
can’t be used to create select menu dropdown, whereas plugin provides niftydropdown_menu()
function that does the job admirably.