4

I did some searching here, but I couldn't find exactly what I was looking for. Is there a template.php function that I can add to change the content title (not the <head> page title) of a user to be a field created after-the-fact (like a first name or the last name field)? If it can't be a function, maybe some type of 'if' statement to wrap around the content title output to check if it's a user page and then output the fields would probably work.

5

Try the Real Name module, it's worked very nicely for me. Here is a quote about it (from the module's project page):

... allows the administrator to choose fields from the user profile that will be used to add a "real name" element (method) to a user object. Hook_user is used to automatically add this to any user object that is loaded. It will also optionally set all nodes and comments to show this name.

| improve this answer | |
6

The page title of the user profile page (like example.com/user/1) is generated by format_username(). If you want to control the username everywhere it occurs in the site, you can implement hook_username_alter in a custom module.

If you just want to change title on the user profile page, you could add THEMENAME_preprocess_page to your template.php to override $variables['title']. An example (untested code):

<?php
/**
 * Preprocess function for page.tpl.php.
 * Replace 'THEMENAME' with the name of your theme.
 */
function THEMENAME_preprocess_page(&$variables) {
  // Only act when the first part of the url equals 'user', the second
  // part is a number and the third part is empty.
  $arg = arg();
  if ($arg[0] == 'user' && is_numeric($arg[1]) && empty($arg[2])) {
    // Do stuff to create the desired username and set the $title variable for the template.
    $variables['title'] = $variables['firstname'] . ' ' . $variables['lastname'];
  }
}
?>
| improve this answer | |
  • Appreciate the insight on this - little new to Drupal, any further help you might be able to give? Thanks. – Zach Nov 5 '11 at 23:49
  • I love to help, but it helps if you have specific questions I can answer. By the way, I would definitely check out the module rfay recommends in his answer. His advice has never let me down. – marcvangend Nov 6 '11 at 7:32
  • Hi @marcvangend Thanks for the response. I guess I'm looking for the actual template.php function that I could use to overrite the page title just on the user profile page with a field I created in the Accounts & Settings area in Drupal 7 (for example, first_name and last_name). Thanks! – Zach Nov 7 '11 at 17:00
  • I'm not talking about overriding a theme function, I'm talking about overriding template variables. I understand that the lingo can be a bit confusing sometimes... I'll update my answer with an example. – marcvangend Nov 7 '11 at 20:06
  • Hi @marcvangend - Sorry, I think we were lost in translation there (my fault). Yes, I was looking for overriding a template variable with what you are talking about above - but unfortunately I get an error - so I revised the parenthesis a bit and don't get an error, but it doesn't seem to be overriding the page title at all: pastebin.com/HPsrKkAr Thanks! – Zach Nov 8 '11 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.