- This topic has 14 replies, 2 voices, and was last updated 3 years, 4 months ago by Elvin.
-
AuthorPosts
-
November 12, 2020 at 1:19 pm #1528949Ruben
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!
November 12, 2020 at 1:34 pm #1528964ElvinStaffCustomer SupportHi Ruben,
Here’s an alternative to Tom’s suggestion:
https://codepen.io/ejcabquina/pen/rNLoZPbIt’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>
.November 12, 2020 at 2:46 pm #1529016RubenThanks 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[i].classList.contains('current-menu-item') ){ var submenu = menu_items[i].getElementsByClassName("sub-menu")[0]; menu_items[i].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?
November 12, 2020 at 2:52 pm #1529021ElvinStaffCustomer SupportTry changing
#primary-menu > ul
to.main-nav > ul
.November 12, 2020 at 3:00 pm #1529029RubenNo, sorry, it doesn’t work yet.
November 12, 2020 at 3:05 pm #1529031ElvinStaffCustomer SupportNo, 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.
November 12, 2020 at 3:18 pm #1529033RubenHi 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.
November 12, 2020 at 3:36 pm #1529042ElvinStaffCustomer Supportah! 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
November 12, 2020 at 3:46 pm #1529046RubenMmm, 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?
November 12, 2020 at 3:50 pm #1529047RubenWell, 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.
November 12, 2020 at 4:45 pm #1529075ElvinStaffCustomer SupportTo 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; }
November 12, 2020 at 5:09 pm #1529084RubenNo, 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.
November 12, 2020 at 5:28 pm #1529100ElvinStaffCustomer SupportNo, 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.
November 13, 2020 at 3:35 am #1529546RubenOh, 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.
November 15, 2020 at 11:40 am #1532583ElvinStaffCustomer SupportNo problem.
-
AuthorPosts
- You must be logged in to reply to this topic.