Created
December 4, 2020 22:09
-
-
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
This file contains hidden or 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 | |
$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