Created
July 8, 2015 13:52
-
-
Save dasginganinja/3332d1ad18025d7fe202 to your computer and use it in GitHub Desktop.
Customizing Page Title for User View pages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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