-
AuthorPosts
-
February 2, 2023 at 2:42 pm #1396400
Hi,
I would like to hide a burger menu item programmatically.
Rikard ask me tu use the following CSS syntax to do it for the main menu : #menu-item-21707 { display: none! ; } and it works fine with main menu but not with burger menu. I tried several syntax but with no success (#av-burger-menu-ul #menu-item-21707).
Many thanks for your help.
Regards
JorgeFebruary 2, 2023 at 3:35 pm #1396406Hi Jorge,
Please try to use this instead:
#av-burger-menu-ul .menu-item-21707
Hope it helps :)
Best regards,
NikkoFebruary 2, 2023 at 3:54 pm #1396412Hi Nikki,
Unfortunately it does not work as well. I already tried.
Another syntax ?
Kind regards
JorgeFebruary 2, 2023 at 5:15 pm #1396425Hi,
To hide the menu item Actualité from the burger menu only on the page /toques-robes/ please try this css:#top.page-id-13355 #av-burger-menu-ul .menu-item-21615 { display: none; }
I added the page ID because your question in the original thread seemed to want to hide the menu item on the specific page, and the menu item class was different than above when I checked.
After applying the css, please clear your browser cache and check.Best regards,
MikeFebruary 3, 2023 at 8:41 am #1396503Hi Mike,
Thank you for your answer. It works fine for this specific page. But the target is to hide this item menu for all pages using this menu. I’m still looking à solution. It’s weird !
Best regards
JorgeFebruary 3, 2023 at 9:05 am #1396510Hi Jorge,
Please us this code to make it work in all pages:
#top #av-burger-menu-ul .menu-item-21615 { display: none; }
If that still does not work, then you can go to Enfold > Main Menu > General (tab) > Alternate Menu For Mobile and use a different menu.
Best regards,
NikkoFebruary 3, 2023 at 9:26 am #1396516The reason for “it works fine with main menu but not with burger menu” is that main menu and burger menu are present the same time, and only visibility is changing. To avoid duplicate IDs (and to preserve html validity), the menu items in the main menu become classes with the same name. So your Menu Item in Main Menu : #menu-item-21707 will be represented in your hamburger menu as .menu-item-21707
An ID should always be unique.February 3, 2023 at 7:26 pm #1396575Hi Guenni,
Thank you for your explanation.
Best regards
JorgeFebruary 3, 2023 at 7:46 pm #1396578Hi Nikko,
Actually, your code works fine in all pages if I put it into the ‘Quick CCS’ box (General Styling) :
#top #av-burger-menu-ul .menu-item-21615 {
display: none;
}
The same (php) code does not work for Burger Menu (ok for main menu) using the following syntax :
?>
<script>
(function($) {
$(“#menu-item-21615”).css(“display”, “none”);
$(“#top #av-burger-menu-ul .menu-item-21615”).css(“display”, “none”);
})(jQuery);
</script>
<?php
What’s wrong ?
Best regards
JorgeFebruary 4, 2023 at 5:40 pm #1396668Hi,
Your script is not going to work because the mobile item is not present until the burger menu is clicked, so when the page loads and the script runs the #top #av-burger-menu-ul .menu-item-21615 is not found.
CSS works because the rule is always available not just on page load, using the CSS solution for this simple rule is the best option but if you really want a script to do it instead try this one:function custom_script() { ?> <script> window.addEventListener('DOMContentLoaded', function() { (function($){ $('#menu-item-21615').css({'display':'none'}); $('.avia_mobile').on('click', '.av-burger-menu-main', function() { $('#top #av-burger-menu-ul .menu-item-21615').css({'display':'none'}); }); }(jQuery)); }); </script> <?php } add_action('wp_footer', 'custom_script');
Best regards,
MikeFebruary 7, 2023 at 11:02 pm #1397051Hi Mike,
Your explanation was very helpful for my understanding. I tried your script and it works fine now. It is so great thanks to you !
I really appreciate your support.
Please close this thread.
Many thanks one more time.
Best regards
JorgeFebruary 8, 2023 at 3:20 am #1397055Hi,
Glad we were able to help, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.Best regards,
Mike -
AuthorPosts
- The topic ‘Hide burger menu item’ is closed to new replies.