Archived topic
Sider top menu collapsed by default
1 reply · Started by Adam on July 11, 2021
Hi There,
I'm using the theme https://gpsites.co/sider/
Looking at a way to have the top menu expanded by default? So all Top Level (Blue in the screenshot) menu items are set to aria-expanded="true" by default but any sub-menu (Red in the screenshot) still stays closed.
Screenshot attached for example
https://drive.google.com/file/d/1CdvpN_oXxUMUPe2FiNbXQbbzwtid4PR7/view?usp=sharing
Hi Adam,
You can use Tom's script here - https://generatepress.com/forums/topic/expand-submenus-on-mobile-with-ability-to-close-each-one-again/#post-1298611 - but modify the selectors.
The script originally was written for all submenu items but we can change that to target a specific one through its menu id.
Each menu item has a unique menu ID, we can use that as a selector.
Example:
<script>
jQuery( document ).ready( function( $ ) {
$( '#menu-item-19262.menu-item-has-children .sub-menu' ).addClass( 'toggled-on' );
$( '#menu-item-19262.menu-item-has-children' ).addClass( 'sfHover' );
} );
</script>
Where menu-item-19262 is the id of the menu item element.