Adding a Second Menu in the Main Divi Header

Written by Dan Mossop

Displaying a second WordPress menu into your Divi header can enhance navigation and offer additional functionalities, such as a language switcher or quick links. This post walks you through adding this secondary menu to your Divi header, with tips on showing or hiding it on different devices.

Adding a secondary menu can be useful for:

  • Language switching with plugins like Polylang.
  • Quick access to key resources or external links.
  • Improved organization by allowing a portion of the menu links to be used elsewhere

Here's and example of how this second menu appears on mobile and desktop:

Adding a Second Main Menu in Divi using PHP and CSS

To add a second menu in your Divi header, follow these steps.

1. Register the new menu and add it to Divi

Add the following PHP code to your child theme's functions.php file or use a plugin like Code Snippets:

function register_my_custom_menu() {
    register_nav_menus(
        array(
            'new-menu-location' => __('My Custom Menu', 'textdomain'),
        )
    );
}
add_action('after_setup_theme', 'register_my_custom_menu');

function display_my_custom_menu() {
    if (has_nav_menu('new-menu-location')) {
        wp_nav_menu(array(
            'theme_location' => 'new-menu-location',
            'container' => 'nav',
            'container_id' => 'top-menu-nav-2',
            'container_class' => '',
            'menu_id' => 'top-menu-2',
            'menu_class' => 'nav',
        ));
    }
}
add_action('et_header_top', 'display_my_custom_menu');

This code registers a new menu location called "My Custom Menu" and displays it in the Divi Header. This new menu will be positioned between the original menu and the search button on desktops and to the left of the mobile menu button on mobile devices.

 2. Style Your Menu

Add the following CSS to "WP Admin > Divi > Theme Options > General > Custom CSS" to style the new menu to match Divi's default look:



#top-menu-2 {
    float: left;
    line-height: 0;
}

#top-menu-2 li {
    display: inline-block;
    font-size: 14px;
    padding-right: 22px;
    word-wrap: break-word;
}

#top-menu-2>li:last-child {
    padding-right: 0;
}

#top-menu-2 .menu-item-has-children>a:first-child {
    padding-right: 20px;
}

#top-menu-2 a {
    color: rgba(0, 0, 0, 0.6);
    text-decoration: none;
    display: block;
    position: relative;
    -webkit-transition: opacity 0.4s ease-in-out, background-color 0.4s ease-in-out;
    transition: opacity 0.4s ease-in-out, background-color 0.4s ease-in-out;
}

#top-menu-2 .menu-item-has-children>a:first-child:after {
    font-family: 'ETmodules';
    content: "3";
    font-size: 16px;
    position: absolute;
    right: 0;
    top: 0;
    font-weight: 800;
}

#top-menu-2 li li a {
    padding: 6px 20px;
    width: 200px;
}

nav#top-menu-nav-2 {
    float: left;
    line-height: 0;
    padding-left: 22px;
    display: inline-block;
}



#top-menu-2 .sub-menu li a {
    border-bottom: 1px solid rgba(0, 0, 0, .03);
    color: #666;
    padding: 10px 5%;
    display: block;
}
#top-menu-2 .sub-menu li a, .nav li li a {
    font-size: 14px;
    -webkit-transition: opacity .2s ease-in-out, background-color .2s ease-in-out;
    transition: opacity .2s ease-in-out, background-color .2s ease-in-out;
}

@media only screen and (max-width: 981px) {
    
    .et_header_style_left #et-top-navigation nav>ul>li>a {
        margin-top: 9px;
    }
    #top-menu-nav-2 {
        margin-left: 22px;
        margin-right: -40px;
        
    }
    #top-menu-2 .sub-menu {
        position: absolute;
        right: -46px;
        padding: 32px;
        background: #fff;
        width: 78vw;
        z-index: 9999;
        border-top: 3px solid #2ea3f2;
        box-shadow: 0 2px 5px rgba(0, 0, 0, .1);
        -moz-box-shadow: 0 2px 5px rgba(0, 0, 0, .1);
        -webkit-box-shadow: 0 2px 5px rgba(0, 0, 0, .1);
    }
	#top-menu-2 li li a {
		width: 66vw;
	}
    

    #top-menu-2 .sub-menu .menu-item-has-children>a {
        font-weight: 700;
        background-color: rgba(0, 0, 0, .03);
    }
}

Note that these styles may need to be tweaked to match any customization you've done to the main Divi menu.

3. Adjust Menu Visibility

Hide on Mobile: If you wish to hide the menu on mobile devices, use the following CSS:

@media only screen and (max-width: 980px) {
    #top-menu-nav-2 {
        display: none !important;
    }
}

Hide on Desktop: Similarly, to hide it on desktops, use:

@media only screen and (min-width: 981px) {
    #top-menu-nav-2 {
        display: none !important;
    }
}

4. Assign your Menu

With this in place, you can now assign a menu to the "My Custom Menu" location in the WordPress menu settings, at:

WP Admin > Appearance > Menus

You're menu should now show up in the second menu spot we've added to the default Divi header.

Run PHP Code Directly in your Divi Layouts

Unlock endless customization, automation, and dynamic functionality by seamlessly adding PHP code to your Divi pages and posts with the Divi PHP Code Module. Style, preview, and debug your PHP creations directly in the visual builder with robust error handling and enhanced security.

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, 

0 Comments

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

Enable Swipe Navigation in the Divi Gallery Lightbox

Enabling swipe navigation in the Divi Gallery module's lightbox allows users to seamlessly browse through gallery images by swiping left or right, creating a more interactive and mobile-friendly experience. This functionality can significantly improve user engagement...

Disable Slide-In Animation for Divi Gallery Grid Images

Control how images appear in your Divi Gallery module by toggling the slide-in animation effect for grid layouts. Disabling the slide-in animation allows gallery images to load instantly and appear statically, providing a faster and distraction-free browsing...

Control Image Count Display in Divi Gallery Lightbox

Displaying or hiding the image count in the Divi Gallery module’s lightbox can help customize the user experience, depending on whether you want to give visitors an indication of gallery progress or prefer a cleaner, distraction-free view. The ability to toggle this...

Hide Gallery Image Titles in the Divi Lightbox Overlay

Displaying image titles in the lightbox overlay of the Divi Gallery module can sometimes be distracting or unnecessary, depending on your website’s design and user experience goals. Hiding these titles creates a cleaner and more focused viewing experience for visitors...

Customize Divi Gallery Module Pagination with Custom Text and Icons

Enhancing the navigation experience in your Divi Gallery module can make your galleries more intuitive and visually appealing for visitors. By replacing the default previous and next pagination links with your own text and icons, you can better align the gallery...

Random Posts