2

I have to make menu for small screen sizes in wordpress template . i want to add some code like below in menu.

<select>
  <option>Home</option>
  <option>About</option>
</select>

wordpress default creating menu through ul li I don't know how to add code in menu. plz anybody can do this?

3
  • 1
    You're going to need to create a custom menu walker. The answers on this question have some resources on how to do this. Commented May 3, 2014 at 15:59
  • is jQuery an alternative for you? Commented May 3, 2014 at 18:38
  • Thats a great idea @wanasten, i've voted up your comment. Commented May 5, 2014 at 10:59

1 Answer 1

1

I am assuming you are creating a responsive site?

If you don't mind some jQuery you can create a select navigation like this:

jQuery( document ).ready(function( $ ) {

  // Create the dropdown base
  $("<select />").appendTo("nav");

  // Create default option "Go to..."
  $("<option />", {
   "selected": "selected",
   "value"   : "",
   "text"    : "Menu"
  }).appendTo("nav select");

  // Populate dropdown with menu items
  $("nav ul li a").each(function() {
   var el = $(this);
   $("<option />", {
     "value"   : el.attr("href"),
     "text"    : el.text()
   }).appendTo("nav select");
  });

  $("nav select").change(function() {
    window.location = $(this).find("option:selected").val();
  });

});

Hide the <select> by default:

nav select {display:none;}

Hide main nav and show <select> on smaller screens:

@media screen and (max-width: 568px) {

  nav select {display:block;}
  nav ul {display:none;}
}
Sign up to request clarification or add additional context in comments.

1 Comment

Yes I use it all the time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.