Skip to content

Instantly share code, notes, and snippets.

@unculturedswine
Created December 4, 2020 22:09
Show Gist options
  • Save unculturedswine/5e5b91d6a3c6daa0a832d96eda5303c4 to your computer and use it in GitHub Desktop.
Save unculturedswine/5e5b91d6a3c6daa0a832d96eda5303c4 to your computer and use it in GitHub Desktop.
Create a dropdown menu of WP Nav Menu links using a <select> wrapper
<?php
$menuLocations = get_nav_menu_locations(); // Retrieves Menus
$menuID = $menuLocations['primary']; // Gets the Primary Menu (Change for your Menu Name)
$primaryNav = wp_get_nav_menu_items($menuID); // Sets up the Foreach Variable
echo '<select>';
foreach ( $primaryNav as $navItem ) {
$link = $navItem->url;
$title = $navItem->title;
echo '<option id="'.$link.'">'.$title.'</option>';
}
echo '</select>';
// From here you would use javascript to trigger the page change
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment