4.7.x theme.inc theme_username($object)
5.x theme.inc theme_username($object)
6.x theme.inc theme_username($object)
7.x theme.inc theme_username($variables)

Format a username.


$object: The user object to format, usually returned from user_load().

Return value

A string containing an HTML link to the user's page if the passed object suggests that this is a site user. Otherwise, only the username is returned.

Related topics

29 theme calls to theme_username()
blog_page_user in modules/blog/blog.pages.inc
Menu callback; displays a Drupal page containing recent blog entries of a given user.
chameleon_comment in themes/chameleon/chameleon.theme
chameleon_node in themes/chameleon/chameleon.theme
comment_admin_overview in modules/comment/comment.admin.inc
Form builder; Builds the comment overview form for the admin.
comment_form in modules/comment/comment.module
Generate the basic commenting form, for appending to a node or display on a separate page.

... See full list


includes/theme.inc, line 1676
The theme system, which controls the output of Drupal.


function theme_username($object) {

  if ($object->uid && $object->name) {
    // Shorten the name when it is too long or it will break many tables.
    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);
  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('attributes' => array('rel' => 'nofollow')));
    else {
      $output = check_plain($object->name);

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

  return $output;


matslats’s picture

If you want to override this function, remember that template_preprocess_node calls this theme hook, passing it a node object, not a user object. So not all passed objects will have 'name' or 'mail' properties. This is a tiny issue except I was storing my themed usernames in a static variable, it cause problems elsewhere.