Removing the (not verified) for Anonymous Users

On drupal sites, anonymous comment and content submitters have (not verified) listed next to their name. There are situations where you don't want this text listed next to anonymous users and earlier this week I was asked how to make this disappear. Let's look at how to remove it.

Note: These instructions are for themes using the phptemplate engine on drupal 5. Phptemplate is the default theme engine.

When a users information, whether anonymous or logged in, is displayed the function theme_username is used to format and sanitize the information. Drupal allows us to override this function with one of our own by creating a function called either phptemplate_username or mytheme_username (replace mytheme with the name of your theme) and placing it in our template.php file.

In this case lets start with the function theme_username and just rename it to phptemplate_username. Then let's comment out or removed the line that adds the (not verified). Stick that in your template.php file and it should work.

Here is what the function looks like:

<?php
function phptemplate_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('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 ($object->homepage) {
     
$output = l($object->name, $object->homepage);
    }
    else {
     
$output = check_plain($object->name);
    }

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

  return
$output;
}
?>

Drupal 6 makes some changes to this function so I wouldn't copy and past this into a drupal 6 installation. But, the same methodology applies. Grab the theme_username from drupal 6, apply the same steps, and you should get the same result.