I want to code a custom menu straight into page.tpl.php. The default theme uses

<?php if ($main_menu): ?>
  <div id="main-menu" class="navigation">
    <?php print theme('links__system_main_menu', array(
      'links' => $main_menu,
      'attributes' => array(
        'id' => 'main-menu-links',
        'class' => array('links', 'clearfix'),
      'heading' => array(
        'text' => t('Main menu'),
        'level' => 'h2',
        'class' => array('element-invisible'),
    )); ?>
  </div> <!-- /#main-menu -->
<?php endif; ?>

In Drupal 7 I've created a new menu called 'Footer menu'. How do I code that into my theme in the same way as the $main_menu is coded in the default theme?

  • Your custom menu will be available as a block, you can simply place that into footer region. This will save you some time and effort. Mar 15, 2013 at 11:22
  • I understand that, however I want to have more control over the output like I would have in the example above
    – tommyf
    Mar 15, 2013 at 11:27

5 Answers 5


Try this

 $menu = menu_navigation_links('menu-your-custom-menu-name');
 print theme('links__menu_your_custom_menu_name', array('links' => $menu));

You can also add to template.php

function THEME_preprocess_page(&$vars) {

$menu = menu_navigation_links('menu-your-custom-menu-name');

$vars['custom_menu'] = theme('links__menu_your_custom_menu_name', array('links' => $menu));


the variable $custom_menu is available in the page tpl

  • I understand that this goes into template.php, but how do I reference the menu in the page template?
    – tommyf
    Mar 15, 2013 at 11:32
  • you can use this code directly in tpl.
    – Sibiraj PR
    Mar 15, 2013 at 11:33

you can override your menu with hook_theme_tree() in template.php:

function THEME_menu_tree__MENUNAME($variables) {
  $menuTree = menu_build_tree('MENUNAME');

  foreach ($menuTree as $item) {


and then create MENU BLOCK Or just print your menu directly in your page.tpl


Well, Nothing from above worked for me with Drupal 7 but below code,

    $search_menu_name = "menu-search-box-menu";

   print theme('links', array('links' => menu_navigation_links($search_menu_name), 'attributes' => array('id' => $search_menu_name, 'class'=> array('links', 'inline'))));

The above code is like this, "menu-search-box-menu" is my custom menu name/ID. You can find it in that particular menu edit link.

Enjoy. :)


I am using bellow code,It's working for me.

$main_menu = menu_navigation_links('menu-main-page'); print($main_menu);


This has been driving me mad.

The easiest way by far is this...

In page.tpl.php where your custom menu name is "Custom Menu"


print drupal_render(menu_tree('menu-custom-menu'));


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.