[Support request] Keep submenu open on current page

Home Forums Support [Support request] Keep submenu open on current page

Home Forums Support Keep submenu open on current page

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #1528949
    Ruben

    Hi there,

    I want to keep the submenu open showing the current page.

    I tried what Tom suggested here: https://generatepress.com/forums/topic/keep-sub-menu-open/#post-927782, but that only keeps the submenu open if you open it once you are already on the current page. If I click on a page of the submenu from a different page when I get there the submenu is closed.

    I don’t know if I am being very clear. Please let me know and I will try to rephrase it.

    Here’s the page I am working on http://www.lamirateca.com/beta/

    Thanks!

    #1528964
    Elvin
    Staff
    Customer Support

    Hi Ruben,

    Here’s an alternative to Tom’s suggestion:
    https://codepen.io/ejcabquina/pen/rNLoZPb

    It’s a JS script w/c you can hook to your wp_footer using Hook Element. Don’t forget to enclose it with a <script> ... </script>.

    A wise man once said:
    "Have you cleared your cache?"

    #1529016
    Ruben

    Thanks Elvin,

    I added the code to a Hook in the wp_footer with the code:

    <script>
    function open_current_menu_submenu(){
    var navmenu = document.querySelector("#primary-menu > ul");
    var menu_items = navmenu.getElementsByClassName("menu-item-has-children");
    	for(i=0;i<menu_items.length;i++){
    		if(menu_items.classList.contains('current-menu-item') ){
    			var submenu = menu_items.getElementsByClassName("sub-menu")[0];
    			menu_items.classList.add('sfHover');
    			submenu.classList.add('toggled-on');
    		}
    	}
    }
    </script>

    And then I checked Execute PHP and show All site.

    But still doesn’t work. Is there anything else I need to do? Any CSS needed?

    #1529021
    Elvin
    Staff
    Customer Support

    Try changing #primary-menu > ul to .main-nav > ul.

    A wise man once said:
    "Have you cleared your cache?"

    #1529029
    Ruben

    No, sorry, it doesn’t work yet.

    #1529031
    Elvin
    Staff
    Customer Support

    No, sorry, it doesn’t work yet.

    Strange. It works perfectly in this demo site. DEMO SITE

    Can you provide us temporary site access to check for any implementation issues?

    You can provide the site details on the private information text field. Thank you.

    A wise man once said:
    "Have you cleared your cache?"

    #1529033
    Ruben

    Hi Elvin,

    Pretty sure the problem must be something I have missed.

    I’ve created a temporary access. It’s here on the private info text.

    Thanks a lot.

    #1529042
    Elvin
    Staff
    Customer Support

    ah! I found the issue.

    My bad, I forgot to add the line that actually runs the script. lol.

    This has to be included:

    document.addEventListener('DOMContentLoaded', (event) => {
        open_current_menu_submenu();
    });

    Codepen updated: https://codepen.io/ejcabquina/pen/rNLoZPb

    A wise man once said:
    "Have you cleared your cache?"

    #1529046
    Ruben

    Mmm, I am afraid it doesn’t work for me yet, even with the code updated.

    I am using a slide-out navigation in the whole site. Does that make any difference in the code needed?

    #1529047
    Ruben

    Well, actually it is kind of working. It does the same that the CSS code did:

    If I open the submenu once I am in the current page, it stays open. But if I go to another page it doesn’t show it open.

    The idea is for the menu to always show you in which page you are.

    #1529075
    Elvin
    Staff
    Customer Support

    To clarify: You want ALL the submenus to stay open on ALL pages?

    If that’s the case then we don’t need the script.

    Try this CSS instead.

    #generate-slideout-menu.main-navigation .main-nav ul ul {
        display: block;
        height: auto;
        visibility: visible;
        position: relative;
        top: 0;
        left: 0;
        width: 100%;
        opacity: 1;
    }

    A wise man once said:
    "Have you cleared your cache?"

    #1529084
    Ruben

    No, let me try to explain it better.

    I would like a single submenu to stay open when one of the pages of that submenu is the current.

    #1529100
    Elvin
    Staff
    Customer Support

    No, let me try to explain it better.

    I would like a single submenu to stay open when one of the pages of that submenu is the current.

    That’s something which will definitely require a significantly more complex site customization scripts.

    Unfortunately, this level of complexity in site customization is out of our scope.

    A wise man once said:
    "Have you cleared your cache?"

    #1529546
    Ruben

    Oh, I was hoping it would be easier than that. It sounded like it kind of made sense to implement that in a slide-out menu when my client asked for it.

    Thanks a lot for looking into this anyway.

    #1532583
    Elvin
    Staff
    Customer Support

    No problem.

    A wise man once said:
    "Have you cleared your cache?"

Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.