-
Wellspring
I have a “menu topper” (another row of nav/links) element that is well-styled at the hook “after_header_content”… including some complex responsive action.
This was working well, until we had to use the streamlined mobile menu. (The content simply does not apply there). Is there a way we can add this hook to the mobile menu in our child theme?
Refactoring all the styling with one of the mobile menu hooks would be tricky, since our element must be after <nav> to respond to sticky classes being added there.
Thanks!
-
Hi there,
Can I see the element on front end of your site?
-
Wellspring
Sure thing; link in private info below!
-
Hi there,
I would use
before_header
hook, and with custom CSS it should work on both desktop and mobile. -
Wellspring
As per my original post, our element must be after
<nav>
to respond to sticky classes being added there. (This is because CSS’s adjacent sibling combinator only works for preceding elements)My question is if there a way we can add a hook to the mobile menu, by utilizing our child theme? Thanks!
-
Wellspring
I have found another solution.
This would still be useful to know, but it’s not longer needed for this site, thanks!
-
As per my original post, our element must be after <nav> to respond to sticky classes being added there.
No, it’s not necessarily to be after <nav>, CSS can be changed.
You just need to add some
margin-top
to the sticky nav to create some space for the container, and add sticky CSS to the container. -
Wellspring
Ying, I appreciate that you are trying to find creative alternative solutions outside of the parameters I have provided. Thank you for this effort. Unfortunately, you seem to have a misunderstanding. My issue is not the positioning of the topper. I’ve been working with CSS for over 20 years. That part is not a challenge.
To clarify, my requirement is to have styling within the .menu-topper respond to the <nav> getting the .sticky-class (Specifically, I have been hiding and reordering some elements in the sticky iteration of the topper)
To do this I have been using a
~
combinator, likenav.sticky-class ~ .menu-topper{flex-order: -1; etc}
. This requires that the menu topper element follows <nav> in the HTML. (This~
used to be called the “general sibling combinator,” but it has been officially renamed to the “subsequent sibling combinator” to clarify that it will not work if the targeted sibling precedes the qualifying sibling.)Anyway, as interesting and informative as this all may be, it does not answer the question that I posted. Given your familiarity with the generate press theme, can you please give some guidance on modifying my child theme to add the hook I need?
-
If the
menu-topper
is not right after thesticky-class
, for example, it’s in thebefore_header
hook, then you can use this CSS selector to target it, will this work for you to save the effort modifying the templates?
body:has(nav.sticky-class) > .menu-topper
-
Wellspring
You are good! (and persistent, lol)
I considered this approach. Honestly don’t recall why it was eliminated. Client may have required 95% support, or something. Ultimately some requirement changed and we used a different solution.
This is really a low-urgency thing now, but I wanted to learn *how* to do that template mod, as we are doing more sites in GPP/GBP. If it’s a headache for you don’t sweat it. Certainly don’t want to distract from the next release. The alpha looks like GREAT progress.
Thanks!
-
can you please give some guidance on modifying my child theme to add the hook I need?
I don’t think it’s possible though, the mobile header is not from GP theme, but GP Premium plugin, there isn’t a template for you to modify, unfortunately.
You will need to re-write the entire function, or try this function which adds
generate_after_header_content
hook intogenerate_inside_mobile_header
hook when viewed on a mobile device, so thegenerate_after_header_content
hook can be used on all devices.add_action('generate_inside_mobile_header', function() { if (wp_is_mobile()) { do_action('generate_after_header_content'); }return; }, 999);
-
Wellspring
Brilliant; thank you so much for the insight, and the solution!
-
You are welcome 🙂
- You must be logged in to reply to this topic.