Making Menus More Responsive
I sometimes need to have certain menu items appear on Desktop, but not Phone. Or other times I need some menu items on Phone, but not Desktop. A great example would be if you have a secondary menu on desktop, but want to show those items in the main menu on Phone, there is no option in Divi or WordPress to do this. But now you can with this trick! In this tutorial I will show you how to show or hide any menu item per device on Desktop, Tablet, and Phone very easily.
▶️ Please watch the video above to get all the exciting details! 👆
Enable CSS Classes In WordPress Navigation Menu Items
The first step is to go to Appearance>Menus from your WordPress Dashboard. Select the menu that you want to edit.
Enable CSS Classes In Screen Options
The key thing here is to make sure CSS Classes is enabled in the Screen Options. At the top of the page, look for the “Screen Options” button, and this opens up some additional options. Find the “CSS Classes” checkbox and select it. Now, inside each menu item will be an additional field for you to add CSS classes. You’ll see what I mean in the screenshots in the next few steps.
Add CSS Classes To The WordPress Navigation Menu Items
Now that you have the CSS classes input field enabled, you can add a classes which we will target to hide the menu item. The CSS class is associated with the menu item. So if we target that class, we are targeting that specific menu item.
By default, a WordPress menu item will display on devices. But in Divi, we have three responsive options – Desktop, Tablet, and Phone. These are based on media queries, which we talk about in another tutorial. So what if you want to show or hide some menu items on different devices sizes?
We start with a CSS class. For the sake of this tutorial, we will keep it simple and use three classes, each will hide the menu item on a specific device size.
pa-menu-hide-desktop
pa-menu-hide-tablet
pa-menu-hide-phone
Just copy and past these classes according to which menu items you want to hide per device. You can watch the video to see this in action. Below is a screenshot to help explain this.
Add CSS Snippets To Show Or Hide Navigation Menu Items
Below you will find three CSS snippets, one for each device size in Divi. You can copy and paste them as needed. Just keep in mind that the class needs to be the same as the ones used in the menu item.
Where To Paste The CSS Code
1. Divi Assistant
If you are using our Divi Assistant plugin, simply paste the code in the CSS tab in the custom code window in the Divi Visual Builder.
2. Child Theme
If you are using a child theme, paste this code into the style.css file. If you don't have a child theme, you can generate a child theme directly on your site or download our free child theme.
3. Divi Theme Options Integration
Otherwise, paste this code in your Divi>Theme Options>Custom CSS code box.
If you need help understanding where to paste the code, please check out our complete guide about where to add custom code In Divi.
Hide Menu Items On Desktop Device Sizes
/*hide menu items on Desktop device sizes*/
@media all and (min-width: 981px) {
.pa-menu-hide-desktop {
display: none;
}
}
Hide Menu Items On Tablet Device Sizes
/*hide menu items on Tablet device sizes*/
@media all and (min-width: 768px) and (max-width: 980px) {
.pa-menu-hide-tablet {
display: none;
}
}
Hide Menu Items On Desktop Device Sizes
/*hide menu items on Phone device sizes*/
@media all and (max-width: 768px) {
.pa-menu-hide-phone {
display: none;
}
}
You can combine these snippets as needed. Just use whichever snippet you need that targets the class in the menu item. Now, when you view your menu, the items will show or hide according to the designated screen size.
Do It With A Setting!
Make life easier and use the Divi Responsive Helper instead, the ultimate Divi responsive toolkit with awesome features and settings to help make your website look and work great on all devices!
Below is a screenshot of the responsive settings our plugin adds to the WordPress Menu items. As you can see, the checkmarks make it super easy to show or hide items on any device.
Hi Nelson
I’m looking to do something similar but slightly different. On the mobile menu (hamburger) version, I have a menu item set to non-clickable using a “#” in the URL, which is desired. The issue is in mobile since there is no mouse pointer, the non-clickable item appears “tappable” and when selected closes the menu. The desired action would be for it NOT to close the hamburger menu. Any way to do this? I would think removing the HREF for this would do it, but can’t figure out how! Thanks, John
Hi John!
Please add the class pa-menu-hide-mobile to the menu item and then add the following code:
@media all and (max-width: 767px){
.pa-menu-hide-mobile a{
pointer-events: none;}
}
Let me know if it helps!