I'm able to get second level of the main menu by using below code.

$menu = '';
$menuItems = menu_tree_page_data('main-menu'); 
foreach($menuItems as $key => $m) {
    if ($m['link']['in_active_trail'] && $menuItems[$key]['below']) {
        $menu = render(menu_tree_output($menuItems[$key]['below']));
print $menu;

If I want to get 3rd (like in image below), 4th or 5th level. how this will be done.

enter image description here

2 Answers 2


It is necessary that you want to display this using code?

I have a better solution for you. You can try with this module Menu Block for above achievement

  • ufff! after exhausted and wasted a lot of time and here you come. Thanks block is working as I expected. Thanks again Commented Apr 14, 2017 at 6:43
  • Menu Block doesn't load Level 3 if Level 1 is selected. however, I have just found a nice_menu that loads all of child. So I'm gonna add as a answer. Commented Apr 20, 2017 at 6:57
  • But nice_menu isn't loads when any active_trail exits. It always load. Its neither fits for my requirement. Commented Apr 20, 2017 at 9:31
  • <?php $main_menu_tree = menu_tree(variable_get('menu_main_links_source', 'main-menu')); print drupal_render($main_menu_tree); ?> Add this on your header menu. Commented Apr 20, 2017 at 11:19
  • And disable menu block. This menu_tree help to render all level which you will add in your menu (selected menu) Commented Apr 20, 2017 at 11:20

I have found a module named Nice_Menus that works for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.