Drupal: hide "(not verified)" for anonymous users

Drupal tags (not verified) to the user name on a comment if the comment was entered by an anonymous user. Although this is technically correct — the name is not from a verified user on your site — I think this looks silly so I wanted to remove it.
There are several ways to accomplish the same. Since hacking the Drupal core should be avoided at all times, one way is to copy the theme_username()
function from theme.inc
, the theming system, and paste it into your template.php
, renaming it to phptemplate_username()
.
You can then modify it to suit your need. Take a look at the function in Drupal 5.16:
<?php
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('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') .')'; // <<<--- This is the line
}
else {
$output = variable_get('anonymous', t('Anonymous'));
}
return $output;
}
?>
I marked the line that adds (not verified) to the user name. Comment out the entire line, or remove it, or change it to read whatever you want.
The advantage is that you can completely customize the function.
However, if all you want to accomplish is to remove the string from the anonymous user's name, you may as well look for a solution in your comment.tpl.php
file. You can use the php function str_replace()
(see php.net for details on the function).
For example, if your comment.tpl.php
is using:
<?php print $submitted; ?>
you can use the php function as follows:
<?php print str_replace(t(' (not verified)'), '', $submitted); ?>
Note the space in " (not verified)". In this case, it simply replaces the string (not verified) with an empty string (works for Drupal 5.x and 6.x). Mission accomplished.
In Drupal 7.x this is an option in the theme settings. A checkbox was added: "User verification status in comments" that makes it easy to toggle this.
Comments
Very useful information.