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 From Divi Booster

How to Add the Post Status in Divi's Dynamic Content

Divi's Dynamic Content feature is great for enhancing your post/page templates with post-specific information. While Divi includes an option to show information such as the Post Created Date using Dynamic Content, there is no equivalent option for the Post Status....

Fix Divi Text Module "Regular" Font Weight Not Working

Are you encountering an issue where the font weights in Divi's Text Module don't seem to apply as expected? In particular, you might find that when you set the text module's body text font weight to "Regular", your font is actually assigned a weight of 500 instead of...

Make the Divi Gallery Module Swipeable

The Divi Gallery Module comes with a slider mode that lets you display images in a slider with clickable left/right arrows to scroll through the images. For mobile / touchscreen users, you can improve the user experience by allowing your user to swipe to navigate to...

How to Use Divi Dynamic Content in Woo Modules Product Selector

Divi's Dynamic Content is a powerful feature that lets you populate your Divi modules and theme builder templates with data pulled in various sources, such as custom fields. This allows for efficient organization and maintenance of your sites.Unfortunately, Divi's...

Random Divi Posts