Hiding Menu Item from the Mobile Menu

Written by Dan Mossop

By default, the Divi Theme shows the same menu items in both the desktop and mobile versions of the header menu (albeit with different formatting). If you'd like to exclude certain items from showing up in the mobile menu, i.e. making them appear on the desktop menu only, here's how to do it.

Add a CSS class to the menu item

From your WordPress dashboard, go to "Appearance > Menus" and in the "Select a menu to edit:" dropdown, select the menu marked "(Primary Menu)". You should now see the menu items making up the menu in your header.

Now, at the top right of the screen you should see a "Screen Options" tab. Click this, and check the "CSS Classes" box, as shown here:

Now, in the Primary menu you just selected from the dropdown, locate the item you wish to hide. Click on it to expand its options and you should see a "CSS Classes (Optional)" field. Enter "desktop-menu-item" into this box. This will add a CSS class to the menu item which we'll use next to hide the items on mobile. If you want to hide more than one item, repeat the process for other items, entering the same CSS class (i.e. "desktop-menu-item") each time. Save the menu.

Hide the Menu Item(s)

Now, add the following CSS to your site:

@media only screen and (max-width: 981px) {
    .desktop-menu-item { display: none; }
}
You can add that CSS at the end of the "Divi > Theme Options > General > Custom CSS" box, or in the style.css file of a child theme.

Now when you view your site, the menu item(s) which have been assigned the CSS class should show on the desktop menu, but not in the mobile menu.

Show Menu Items with a CSS Class

If you'd prefer to show only certain menu items, you can give those items a CSS class as above (you may want to choose a different class name, such as "mobile-menu-item" as I do here), and hide the rest with this CSS:

@media only screen and (max-width: 981px) {
    #mobile_menu li:not(.mobile-menu-item) { 
        display: none; 
    }
}

Hide a menu item, but not its submenu items

To hide a menu item, but show the menu items nested underneath the hidden link, give the "parent" menu items you want to hide a CSS class as above (I'm using "hidden-menu-item" here), and hide them with this CSS:

@media only screen and (max-width: 981px) {
    #mobile_menu li.hidden-menu-item > a {
        display: none;
    }
}

Streamline Your Divi Experience with Powerful Plugins

Looking to enhance your Divi site's functionality? Discover how you can streamline your workflow and boost user interaction with our innovative plugins. Whether you're managing menus or enhancing your pages with dynamic CTAs, we've got the perfect solution for you.

About Dan Mossop

Dan is a Scottish-born web developer, now living in Brisbane with his wife and son. He has been sharing tips and helping users with Divi since 2014. He created Divi Booster, the first Divi plugin, and continues to develop it along with 20+ other Divi plugins. Dan has a PhD in Computer Science, a background in web security and likes a lot of stuff, 

5 Comments

  1. This code worked perfectly, but how do I hide a menu item, but show the menu items nested underneath the hidden link?

    Reply
    • Hi Carrie, I've just added a section to the post describing how to do this. Hope it helps!

      Reply
    • I was wondering, would it be possible to turn this around? So that you put some CSS in the menu items that you would like to show, and hide the others which do not have that CSS line?

      Reply
      • Hey Maarten, I've just added a section at the end of the post describing how to do this. Hope it helps!

        Reply

Submit a Comment

Comments are manually moderated and approved at the time they are answered. A preview is shown while pending but may disappear if your are cookies cleared - don't worry though, the comment is still in the queue.

Your email address will not be published. Required fields are marked *.

We may earn a commission when you visit links on our website.

Latest Posts

How to Hide a Divi Module When Scrolling Up or Down

In this quick tutorial, I’ll show you how to hide a Divi module when scrolling in a specific direction (up or down), so that the module only shows when you want it to. This is especially useful when using Divi’s Scroll Effects feature and you have a effect you want to...

Fade a Divi Image Module Edge into the Background

Want to create a stylish fade effect on your Divi image module—where one side fades smoothly into the background? With a bit of CSS, you can make any edge (or corner) of the image fade out: top, bottom, left, right, or even diagonally.Fade a Divi Image Module Edge...

Hide the Header and Footer in the Hello Elementor Theme

Removing the default header and footer from your Hello Elementor theme allows for a streamlined and distraction-free website design. This is especially useful when creating unique landing pages, full-width layouts, or custom headers and footers with a page builder. In...

Setting up the Divi Password Box Module

Setting up password protection on a page can help you control access to sensitive or private content in WordPress, allowing only authorized visitors to view certain sections. With the Divi Password Box module, you can replace the plain Divi password form with a fully...

Open Divi Social Media Icons in a New Tab

Ensuring your website's social media icons open in a new browser tab creates a seamless user experience and keeps visitors engaged with your site while allowing them to explore your social media presence. This approach prevents users from navigating away from your...

Random Posts