Main menu

In my last post I explained how to hide menu-tabs that were defined by a Drupal module without actually losing the module’s functionality. Now we’ll see how to change the title of menu-items.

Changing the tabs on the “/user” page

For example, let’s change the “Create new account” and “Request new password” menu tabs on the “/user” page as shown below.

Changing menu-items titles

In a similar fashion like we used hook_menu_alter and changed the menu-items “type” to hide menu-items, we need to change a menu-items specification to alter the title.

This time we target the title attribute. Doing so we can override the existing title with something else.

So we target the title attribute of menu-items within a hook_menu_alter:

/**
 * Implements hook_menu_alter().
 *
 * We want to change the menu-items titles on the login form.
 */
function gluecode_menu_alter(&$items) {
  $items['user/register']['title'] = 'Feel like joining?'
  $items['user/password']['title'] = 'Lost your password?';
}

And this changes the “Create new account” and “Request new password” links to “Feel like joining?” and “Lost your password?” as shown below.

3 comments

Default avatar
Dom
Tue, 05/04/2011 - 21:31

Hello, Sorry, but I started two months ago with Drupal, which file to put this code? Also can you tell me how to display menus with three levels of navigation, as here from the "pages": http://demo.kiwi-themes.com/node/102 (default none appears to activate the theme Titan) Thank you
Default avatar
Toon Ketels
Sun, 10/04/2011 - 12:39

Hi, 1. You should create a custom module and put the code in there. For each website you could create a custom 'gluemodule' in which you put project specific code such as this one. In short, to create a module named 'gluemodule', create a directory 'gluemodule' with a 'gluemodule.info' and 'gluemodule.module' file. Put the code in the 'gluemodule.module' file. For more information see http://drupal.org/developing/modules. 2. Use the module 'menu block' to display a menu N-level deep. See project at http://drupal.org/project/menu_block.
Default avatar
Juicy Couture
Mon, 19/03/2012 - 07:11

The content of this field is kept private and will not be shown publicly.