Authored by Drupal Geeks on 14 Oct 2021
Bootstrap sub menu

Working on a Drupal website? Kicking off with Bootstrap or its starterkit? Well! The first main issue that we encounter is with the Bootstrap Main Menu. The Bootstrap theme package lacks rendering submenus with multiple levels by default. This compels us to install a module similar to ‘Nice Menus’ to enable multi-level submenus. But the solution comes really simple by making use of a small section of code, keeping the website lightweight.

Assume that the primary menu involves a hierarchy as provided in the screenshot.


The default bootstrap menu rendered in Drupal will display only the first level of submenus from the hierarchy.


This can be fixed by the following steps,

Step 1:

Navigate to the Primary Menu management page as the administrator via admin/structure/menu/manage/main-menu.

Step 2:

The listing page displays all the links present in the Main Menu.

From the edit page of each menu link, ensure that the “Show as Expanded” checkbox is checked. 


Step 3:

Now add the following code to sites/all/themes//template.php

Ensure that the function name is renamed to the theme’s appropriate hook name by replacing the word hook with your theme name. ie. If your theme name is bootstrap or menubootstrap then the function name should be bootstrap_menu_link__main_menu and menubootstrap_menu_link__main_menu respectively.

function hook_menu_link__main_menu($variables)
  $element = $variables['element'];
  $sub_menu = '';
  if ($element['#below']) {
    // Prevent dropdown functions from being added to management menu so it
    // does not affect the navbar module.
    if (($element['#original_link']['menu_name'] == 'management') && (module_exists('navbar'))) {
      $sub_menu = drupal_render($element['#below']);
    } elseif ((!empty($element['#original_link']['depth'])) && $element['#original_link']['depth'] > 1) {
      // Add our own wrapper.
      $sub_menu = '


Step 4:

Add the following css in one of your stylesheets or in


  • /css/overrides.css
  • '>

    .dropdown-submenu>.dropdown-menu{top:0;left:100%;margin-top:-6px;margin-left:-1px;-webkit-border-radius:0 6px 6px 6px;-moz-border-radius:0 6px 6px;border-radius:0 6px 6px 6px}
    .dropdown-submenu>a:after{display:block;content:" ";float:right;width:0;height:0;border-color:transparent;border-style:solid;border-width:5px 0 5px 5px;border-left-color:#ccc;margin-top:5px;margin-right:-10px}
    .dropdown-submenu.pull-left>.dropdown-menu{left:-100%;margin-left:10px;-webkit-border-radius:6px 0 6px 6px;-moz-border-radius:6px 0 6px 6px;border-radius:6px 0 6px 6px}

    Step 5:

    Now clear the website’s cache. This can be done by clicking on “Clear all caches” button present in the page admin/config/development/performance. The entire bootstrap menu with all sublevels will now be rendered.



    If your business is in need of a new or improved website to establish or enhance its internet presence, you should seriously consider using one of the many Bootstrap themes in Drupal offered by DrupalGeeks. You can expect a wide variety of themes and templates to choose from, friendly and professional customer service, and all the technical support you might need to get started. If customization is required, DrupalGeeks can assist with that as well, so you end up with exactly the kind of website that will be best for your company.