[Drupal] How to display the main menu in two different blocks in a Drupal site?

| | 1 min read

One of our Drupal clients requested us to display the main menu in two different blocks on the same Drupal site. If you want to know how to place the same menu in two different blocks in your Drupal site then read on to know how we figured it out without duplicating code.

Just follow the steps below.

  • The effect can be achieved easily by using the hook_page_alter
  • The following code will place the Main menu of the header region in the footer region
    function MODULEHOOK_page_alter(&$page) {
      $menu_block = $page['header']['main-menu'];
      $page['footer']['main-menu'] = $menu_block;
    }
  • You should be able to place the menu in any other region in your Drupal site using a variation of the above code

If you need professional assistance in configuring the blocks and regions in your Drupal site get in touch with us