Monthly Archives: November 2014

Display only the first menu link in Drupal 7

This is a useful Drupal 7 code snippet that can echo out the first (or whatever link you prefer) link in a menu. Recently, I used this to create a menu with one link used for a Donation button. I wanted to prevent any other items being echoed or inserted into a block area, so I used this so that the first menu item was always the only one that would be shown. It was useful since, on other pages, the full menu with other links under “Donate” was used in Block form.

<?php
$menu_depth = 1;
$menu_tree = menu_tree_output(menu_tree_all_data('menu-donate', null, $menu_depth));
print drupal_render($menu_tree);
?>