Site logo

Archived topic

Navigation hooks - loading element in mobile and dekstop separate

1 reply · Started by Lucas on February 14, 2022

Viewing posts 1–2 of 2

Hello,

I'm trying to integrate an extra element after the main navigation.
Which has some elements within it that have an ID associated to them which I need to call for some jQuery (for dropdown functionality).

But I can't find a way to implement my extra element with the current hooks.
Because most of them make it so the element is loaded in both the mobile menu as in the desktop version.
Which makes it so my ID specific code not to work on my element, because it is being loaded in twice.

The closest thing I got is the following.
Use the generate_inside_navigation to load in for desktop.
And use the generate_inside_mobile_header to load in for mobile.
But the issue here is for desktop the element is loaded in before the main navigation.
I'm able to change the order of these elements using CSS but this will make tabbing through the navigation go in a strange order.
It would be better if it would be in the correct flow.

Is there a way for me to make it so I can load in the code separate for mobile and desktop with the standard hooks within Generatepress?
I rather avoid adding custom hooks if necessary.

Thanks in advance

Hi there,

so the generate_menu_bar_items hook sounds like the one you're using and is in the correct place but has the duplication issue. GP uses this function to add that hook: generate_do_menu_bar_item_container

And here you can see where that function callback is being made:

https://github.com/tomusborne/generatepress/blob/adfe090929b0515cdf894f4c6b722cfe8c0790dc/inc/structure/navigation.php#L460-L461

So if i understand correctly and you need to hook in a different element for desktop and mobile, then try these:

Desktop: generate_after_primary_menu
Mobile: generate_inside_mobile_menu_control_wrapper

This archived topic is closed to new replies.