Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WordPress Menu as Select Dropdown (js)
jQuery(document).ready(function($){
// Create the dropdown base
$('<div class="mobile-menu"><form><select onchange="if (this.value) window.location.href=this.value" /></form></div>').prependTo("#wrap");
// Create default option "Go to..."
$("<option />", {
"selected": "selected",
"value" : "",
"text" : "Go to..."
}).appendTo(".mobile-menu select");
// Populate dropdown with menu items
$("#nav a").each(function() {
var el = $(this);
$("<option />", {
"value" : el.attr("href"),
"text" : el.text()
}).appendTo(".mobile-menu select");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.