Search code examples
drupaldrupal-7drupal-routes

Modify the title given in hook_menu() from another module


How can I change the title given to the /user/[uid] page from Your account to Welcome [user name] for logged-in user, where [user name] is the username for the currently logged-in user?


Solution

  • Use hook_menu_alter.

    Alter the data being saved to the {menu_router} table after hook_menu is invoked.

    Code sample:

    function MYMODULE_menu_alter()
    {
        global $user;
        if($user->uid != 0)
            $items['user']['title'] = 'Welcome ' . $user->name;
    }