Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WordPress TwentyFifteen submenu items to display when parent/sibling page is active

To improve my WordPress TwentyFifteen child theme on GitHub, I would like submenu items to display when the parent/sibling page is active.

On startup, the menu should remain compact (as it currently does in TwentyFifteen), like this:

  • Page 1
  • Page 2
  • Page 3

When the user opens any top-level page, the menu should auto-expand to reveal submenu items, like this:

  • Page 1
    • subpage a
    • subpage b
  • Page 2
  • Page 3

Currently, these submenu items appear ONLY when the user clicks specifically on the menu down-arrow (a small icon that most users do not see). Instead, my goal is for submenu items to appear whenever the parent page is active.

There are related solutions that address similar issues, but not my issue in Twenty Fifteen:

  • https://mpswp.wordpress.com/2015/06/27/twenty-fifteen-theme-reveals-hidden-submenus
like image 285
jackdougherty Avatar asked Dec 30 '25 23:12

jackdougherty


2 Answers

@hareesh-sivasubramanian's answer is enough to get the menu displayed but doesn't "tell" Twenty Fifteen that the menu is open. Therefore, to close the submenu, you have to click the toggle button twice!

I fixed this by combining the accepted answer with a small custom jQuery to click the button so that it's toggled:

( function( $ ) {

    $( document ).ready( function() {
        $('.main-navigation .nav-menu > .current-menu-item > button').click();
    });

} )( jQuery );
like image 87
mrwweb Avatar answered Jan 04 '26 01:01

mrwweb


Add this CSS to your stylesheet.

.main-navigation ul .current-menu-item ul {
    display: block;
}
like image 41
Hareesh Sivasubramanian Avatar answered Jan 04 '26 01:01

Hareesh Sivasubramanian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!