Skip to content

Instantly share code, notes, and snippets.

Created August 7, 2012 17:06
What would you like to do?
WordPress Menu as Select Dropdown (js)
// 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