How can I change the title of the User Menu to display the name of the user?

Comments

komal.savla’s picture

Hi,

Add this code in template.php inside the function corolla_preprocess_block(&$variables)

 if($variables['block']->delta == 'user-menu' ) {
    global $user;
    $variables['block']->subject = $user->name;
  }

This will change the title of the user menu block to the name of the user

Thanks,
Komal

glennnz’s picture

Status: Active » Closed (fixed)

Perfect, thanks

cptlonestar’s picture

Component: Other » Code
Issue summary: View changes

Hi,

This really helped with getting the name to appear above my user menu when someone is logged in. However, when no one is logged in, the user menu (which also appears in my footer) doesn't have a title. Is anyone able to help me with the simple programming for adding a title such as "Members" when no one is logged in/anonymous user?

Any help would be greatly appreciated.

cptlonestar’s picture

Status: Closed (fixed) » Active
glennnz’s picture

@Cptionestar

Try this:

<?php
global $user;
if ($user->uid) {
  if($variables['block']->delta == 'user-menu' ) {
    $variables['block']->subject = $user->name;
  }
}
else {
  $variables['block']->subject = t('Anonymous');
}
?>

Glenn

glennnz’s picture

Status: Active » Closed (fixed)

Change 'Anonymous' to whatever you want the block title to be.