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");
});
});
view raw mobile-menu.js hosted with ❤ by GitHub

Bill Erickson

Bill Erickson is the co-founder and lead developer at CultivateWP, a WordPress agency focusing on high performance sites for web publishers.

About Me
Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk