Skip to content

Instantly share code, notes, and snippets.

@dasginganinja
Created July 8, 2015 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dasginganinja/3332d1ad18025d7fe202 to your computer and use it in GitHub Desktop.
Save dasginganinja/3332d1ad18025d7fe202 to your computer and use it in GitHub Desktop.
Customizing Page Title for User View pages
/**
* Implements hook_menu_alter().
*/
function MYTHEME_menu_alter(&$items) {
$items['user/%user']['title callback'] = 'MYTHEME_user_page_title';
}
/**
* Custom Callback for setting page title.
*/
function MYTHEME_user_page_title() {
if (arg(0) == 'user') {
// Load uid from url
$user = user_load(arg(1));
$wrapper = entity_metadata_wrapper('user', $user);
$first_name = $wrapper->field_profile_first_name->value();
$last_name = $wrapper->field_profile_last_name->value();
if ($first_name && $last_name) {
drupal_set_title('User Profile - ' . $first_name . ' ' . $last_name);
}
else {
drupal_set_title('User Profile');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment