WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In the twenty-twelve theme, the following code will collapse the sub-menu ul/li on the mobile version. The problem is that it also breaks the normal version of the menu. How can I use it only when the mobile menu comes in?

    $('.main-navigation li ul').hide();
    $('.main-navigation li').has('ul').click(function() {
share|improve this question
What's wrong with the native menu? Twentytwelve does this by default out of the box, why do you need jQuery? – vtacreative Apr 10 '13 at 0:29
maybe i was not clear in my description but twenty twelve doesn't collapse the sub-pages as this jquery does. please note, i don't mean collapse the entire menu into the menu button...i mean collapse only the voices that have sub-voices so that if you click on them they will expand and show the sub-pages... – kasuga Apr 10 '13 at 7:59
@CL75 hi...any idea? – kasuga Apr 16 '13 at 18:15
Do you have a visual? Or a working example from a different site? I'm not sure if I understand just what you're trying to accomplish. – vtacreative Apr 16 '13 at 22:55
@CL75 no i'm sorry, i only found the script...i try to explain again: the subpages must be collapsed in the parent page so that the mobile menu will be shortered. when you click on the parent page the menu expands itself and you will see the subpages link... – kasuga Apr 18 '13 at 11:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.