Tuesday, April 21, 2015

Overriding the user menu title function for change My account as username

Replacing My account label with the username in drupal user menu. I have not found any module for this but we can do it by hacking(Not a good Practice) in Drupal user module file
in modules/user/user.module line:2035
/**
 * Menu item title callback for the 'user' path.
 *
 * Anonymous users should see "User account", but authenticated users are
 * expected to see "My account".
 */
function user_menu_title() {
 //return user_is_logged_in() ? t('My account') : t('User account');
}

Change with
  return user_is_logged_in() ? $GLOBALS['user']->name : t('User account');

Reference
https://www.drupal.org/node/1760634
http://www.ipsure.com/blog/2012/showing-username-instead-of-my-account-in-drupal-7/