- This topic has 16 replies, 6 voices, and was last updated 2 years, 11 months ago by
Fernando.
-
AuthorPosts
-
July 3, 2022 at 2:56 am #2271615
Jean-Charles
Hi,
I try to add an element with hook inside mobile menu.
But I try all the hooks but the element doesn’t go in the right navigation.
My mobile menu is like this :<nav id="mobile-header"> ... <div id="mobile-menu"> ... </div> </nav>And all the mobile hook are inside
<nav id="mobile-menu-control-wrapper">
But this nav is hidden in mobile…You could search in DOM “Mobile elements” here https://colisee.incognito.digital/
Any idea ?
BestJuly 3, 2022 at 4:07 am #2271659David
StaffCustomer SupportHi there,
did you resolve this ? As i see the
mobile-menu-langueelement in thereJuly 3, 2022 at 10:45 am #2272032Jean-Charles
Nope I didn’t resolve it.
I saw that my mobile menu is inside
<nav id="mobile-header">
And the mobile hook appear un <header>
I think that my mobile menu isn’t in the right place, but i don’t know why.
Best.
JCJuly 3, 2022 at 11:10 am #2272043Jean-Charles
I find where this menu is generate :
line 1051 in gp-premium/menu-plus/functions/generate-menu-plus.php file
Best
JCJuly 3, 2022 at 12:47 pm #2272094Ying
StaffCustomer SupportHi there,
Can you tell me where you want your element to show up exactly visually on mobile?
I marked it in the blow screenshot, can you check if that’s the position you want your element to be?
https://www.screencast.com/t/RzgUeWKouIJuly 3, 2022 at 11:13 pm #2272324Jean-Charles
Hi Ying,
Yes! exactly here 🙂
BestJuly 3, 2022 at 11:52 pm #2272347Fernando Customer Support
Hi Jean-Charles,
I see. There’s no hook in that specific location. You would need to add a snippet to add a custom Hook there:
add_shortcode('portable_hook', function($atts){ ob_start(); $atts = shortcode_atts( array( 'hook_name' => 'no foo' ), $atts, 'portable_hook' ); do_action($atts['hook_name']); return ob_get_clean(); }); add_filter( 'wp_nav_menu_items', 'prefix_add_div', 15, 2 ); function prefix_add_div( $items, $args ) { if( $args->theme_location != 'primary' ) { return $items; } $items .= '<li class="menu-item custom-menu-item">'.do_shortcode( '[portable_hook hook_name="generate_custom_primary_menu"]' ).'</li>'; return $items; }Adding PHP reference: https://docs.generatepress.com/article/adding-php/#code-snippets
With this, you’ll have a new custom Hook called
generate_custom_primary_menu. You can use it as such: https://share.getcloudapp.com/9ZuoD7j9You’ll then need to add this custom CSS to hide the new menu item in other view.
@media (min-width: 769px) { .custom-menu-item { display: none; } }Hope this helps!
July 4, 2022 at 1:23 am #2272395Jean-Charles
Thx a lot, it’s nearly work 🙂
But my elements appear in all my menu ( primary, language, footer etc.)
https://tinyurl.com/2bdubjllBest.
JCJuly 4, 2022 at 1:31 am #2272398Fernando Customer Support
I see.
I modified the PHP snippet above. Can you try that instead?
Kindly let us know how it goes.
July 4, 2022 at 2:10 am #2272428Jean-Charles
Nice,
You are the best,
Thx to all the teams 🙂
Best
JCJuly 4, 2022 at 4:58 pm #2273214Fernando Customer Support
You’re welcome JC! Glad that worked! 🙂
October 4, 2022 at 5:19 pm #2363402Jonathan
Hi,
what need to be changed in the php code above to have this hook at the beginning of the mobile menu instead of the last item?Thanks
October 4, 2022 at 7:06 pm #2363457Fernando Customer Support
Try this:
add_shortcode('portable_hook', function($atts){ ob_start(); $atts = shortcode_atts( array( 'hook_name' => 'no foo' ), $atts, 'portable_hook' ); do_action($atts['hook_name']); return ob_get_clean(); }); add_filter( 'wp_nav_menu_items', 'prefix_add_div', 15, 2 ); function prefix_add_div( $items, $args ) { if( $args->theme_location != 'primary' ) { return $items; } $items = '<li class="menu-item custom-menu-item">'.do_shortcode( '[portable_hook hook_name="generate_custom_primary_menu"]' ).'</li>'. $items; return $items; }October 4, 2022 at 7:41 pm #2363484Jonathan
it works well thank you
October 4, 2022 at 7:52 pm #2363495Fernando Customer Support
You’re welcome Jonathan!
-
AuthorPosts
- You must be logged in to reply to this topic.