How To Collapse Submenus In Divi

by | Jan 5, 2022 | Divi Tutorials

Customize the mobile menu with this easy to follow Javascript and CSS snippet! Making submenus collapse keeps the long mobile menus clean and responsive. It works with the Divi menu module and standard Divi header.

Before

divi collapse submenus mobile header1
divi collapse submenus mobile header1

After

divi collapse submenus mobile header2
divi collapse submenus mobile header2

For doing this you have to just add CSS & javascript to your Divi website.

CSS

Navigate to Theme Options and scroll down to bottom and add this code to Custom CSS.

.et_pb_menu .et_mobile_menu .menu-item-has-children > a,
#main-header .et_mobile_menu .menu-item-has-children > a {
    background-color: transparent;
    position: relative;
}

.et_pb_menu .et_mobile_menu .menu-item-has-children > a:after, #main-header .et_mobile_menu .menu-item-has-children > a:after {
    font-family: 'ETmodules';
    text-align: center;
    speak: none;
    font-weight: 600;
    font-variant: normal;
    text-transform: none;
    -webkit-font-smoothing: antialiased;
    position: absolute;
    font-size: 18px;
    content: '4c';
    top: 11px;
    right: 13px;
}

.et_pb_menu .et_mobile_menu .menu-item-has-children.visible > a:after,
#main-header .et_mobile_menu .menu-item-has-children.visible > a:after {
    content: '4d';
}

.et_pb_menu .et_mobile_menu ul.sub-menu,
#main-header .et_mobile_menu ul.sub-menu,
.et-db #et-boc .et-l .et_pb_menu .et_mobile_menu li ul.sub-menu {
    display: none !important;
    visibility: hidden !important;
    transition: all 1.5s ease-in-out;
}

.et_pb_menu .et_mobile_menu li.visible > ul.sub-menu,
#main-header .et_mobile_menu li.visible > ul.sub-menu,
.et-db #et-boc .et-l #main-header .et_mobile_menu li.visible > ul.sub-menu,
.et-db #et-boc .et-l .et_pb_fullwidth_menu .et_mobile_menu li.visible > ul.sub-menu,
.et-db #et-boc .et-l .et_pb_menu .et_mobile_menu li.visible > ul.sub-menu {
    display: block !important;
    visibility: visible !important;
}

JavaScript

Navigate to Theme Options > Integration > Add code to the < body >.

<script>
jQuery(document).ready(function($){
    function ds_setup_collapsible_submenus() {
        var $menu = $('.et_mobile_menu'),
        top_level_link = '.et_mobile_menu .menu-item-has-children > a';
        
        $menu.find('a').each(function() {
            $(this).off('click');
            if ( $(this).is(top_level_link) ) {
                $(this).attr('href', '#');
            }

            if ( ! $(this).siblings('.sub-menu').length ) {
                $(this).on('click', function(event) {
                    $(this).parents('.mobile_nav').trigger('click');
                });
            } 
            else {
                $(this).on('click', function(event) {
                    event.preventDefault();
                    $(this).parent().toggleClass('visible');
                });
            }
        });
    }
    setTimeout(function() {
        ds_setup_collapsible_submenus();
    }, 700);
 });
</script>

The Bottom Line

We hope that this method works for you. Comment down your review about this blog.

License: This snippet contains code from the Divi Theme, copyright https://elegantthemes.com.

Latest Posts

Top 5 Appointment Booking WordPress Plugins (2025 Edition)

Top 5 Appointment Booking WordPress Plugins (2025 Edition)

What to Look for in a Great Appointment Booking Plugin1. Calendar View and Availability Management2. Payment Integration3. Notifications and Reminders4. Google Calendar Sync5. Speed and Lightweight Design6. Ease of Setup and CustomizationTop 5 Appointment Booking...

Top 5 Free India Payment Gateways for your WordPress Website

Top 5 Free India Payment Gateways for your WordPress Website

Why Choosing the Right Payment Gateway MattersTop 5 Free Best Payment Gateways for WordPress in India (2025)RazorpayInstamojoPayPal IndiaStripeCashfree PaymentsComparison Table: Best Indian Payment Gateways for WordPress (2025)How to Integrate a Payment Gateway in...

Top 5 SEO plugins for WordPress Website

Top 5 SEO plugins for WordPress Website

What Makes a Good WordPress SEO Plugin?Top 5 SEO Plugins for WordPress (2025 Edition)1. Rank Math SEO (Best Overall Plugin)2. Yoast SEO (Most Popular & Beginner-Friendly)3. All-in-One SEO (Best for Businesses & WooCommerce)4. SEOPress (Best Lightweight SEO...

Top 10 SEO Friendly WordPress Theme

Top 10 SEO Friendly WordPress Theme

What Makes a WordPress Theme SEO-Friendly?Top 10 SEO Friendly WordPress Themes for 2025AstraGeneratePressKadenceOceanWPNeveSchema by MyThemeShopHello ElementorSydneyZakraBlocksyComparison Table - SEO Features at a GlanceFree vs Premium SEO WordPress ThemesHow to...

ChatGPT 5.2 Features and Breakthroughs You Need to Know

ChatGPT 5.2 Features and Breakthroughs You Need to Know

ChatGPT 5.2 vs 5.1: What is New and Why It MattersThe Evolution Timeline: How We Got From 5.0 to 5.1 and Now to 5.2ChatGPT 5.0ChatGPT 5.1ChatGPT 5.2What ChatGPT 5.1 Introduced1. Dynamic Memory Layer2. Custom Experience Controls3. Better Code and Fact Handling4. Early...

Mayank Kumar is the Founder and CEO of Web Wallah. He is a Digital Growth Strategist who has scaled 100+ brands with SEO, high-performing websites, and ads delivering 6–8x ROAS. As a professional speaker and WordPress mentor, he also contribute as an organiser of the WordPress Delhi Community and the n8n India Community (Unofficial).

Latest Posts

WhatsApp