I'm trying to change the user page titles from username (var 'name') to the user's FULL NAME which is a custom field I created when registering. How do I change or even just remove the username as a page title and input my own? I can't seem to find the modifier or any file associated to where that information is being inputted anywhere?

Comments

vm’s picture

token and pathauto ? if they can't do it , it may shed some light on how to.

_____________________________________________________________________
My posts & comments are usually dripping with sarcasm.
If you ask nicely I'll give you a towel : )

alan d.’s picture

There probably many ways to do this, personaly I like code as this doesn't require additional modules slowing things down.

<?php
// Special module hook to the profiles template load
function MYMODULE_preprocess_user_profile(&$variables) {
  $name = theme_username($variables['account']);
  drupal_set_title($name . ' the name');
}

// But this one would probably do the trick :)
// it themes all user names in the system, from titles to comment by ...
// theme_username is defined in theme.inc
function phptemplate_username($object) {
  return theme_username($object);
}

?>

Just remember to FLUSH your cache. OTherwise these hooks will never be picked up.

The first function requires a custom module, the second goes in the themes template.php file

Cheers


Alan Davison
www.caignwebs.com.au

Alan Davison
shali.nguyen’s picture

Alan,

I'm not really sure where to put this code or how to create a module. Can you elaborate a little bit as I am new to this? thank you so much!!!

vm’s picture

use either or.

since you are new try the second snippet, which goes in template.php of your theme

_____________________________________________________________________
My posts & comments are usually dripping with sarcasm.
If you ask nicely I'll give you a towel : )

shali.nguyen’s picture

Where do I tell it to use "full name" instead of username? Right now it is only pulling the username in the profile page. see for reference: http://shalinguyen.com/username.gif

alan d.’s picture

Right, I didn't actually give the code to change the username, just the code to hook into the system to allow you to define your own specifications.

So, firstly lets copy the code from theme.inc and rename the theme_ to phptemplete_ and throw that into your themes template.php file and flush the cache. Then do the changes that you require.

The example below just needs the THE_VAR_FIRST_NAME && THE_VAR_LAST_NAME replaced.

You can grab the variable name from the profiles page, (eg "profile_XXXXX")

<?php
function phptemplate_username($object) {
  //dpr($object->uid && $object->name);
  if ($object->uid && $object->name) {
    //Probably just ave a node, being lazy and loading the user object
    $user = user_load(array('uid' =>  $object->uid));
    // Shorten the name when it is too long or it will break many tables.
    $object->name = ($user && (!empty($user->THE_VAR_FIRST_NAME) && !empty($user->THE_VAR_LAST_NAME)))
      ? $user->THE_VAR_FIRST_NAME . ' ' . $user->THE_VAR_LAST_NAME
      : $user->username;
    if (drupal_strlen($object->name) > 20) {
      $name = drupal_substr($object->name, 0, 15) .'...';
    }
    else {
      $name = $object->name;
    }

    if (user_access('access user profiles')) {
      $output = l($name, 'user/'. $object->uid, array('attributes' => array('title' => t('View user profile.'))));
    }
    else {
      $output = check_plain($name);
    }
  }

  // we can not assume that we have an user anymore...

  else if ($object->name) {
    // Sometimes modules display content composed by people who are
    // not registered members of the site (e.g. mailing list or news
    // aggregator modules). This clause enables modules to display
    // the true author of the content.
    if (!empty($object->homepage)) {
      $output = l($object->name, $object->homepage, array('rel' => 'nofollow'));
    }
    else {
      $output = check_plain($object->name);
    }

    $output .= ' ('. t('not verified') .')';
  }
  else {
    $output = variable_get('anonymous', t('Anonymous'));
  }

  return $output;
}
?>

Let me know if you have any hassles.


Alan Davison
www.caignwebs.com.au

Alan Davison