Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Use the following PHP code in a custom token to display the comment author's name as a link to either their homepage or their user profile. If they didn't enter a homepage URL and they're an anonymous user, or if accessing user profiles is not allowed, the comment author's name will be displayed without a link.
Set the 'token type' to 'Comments'.
$comment = $data['comment'];
$name = $comment->name;
$homepage = $comment->homepage;
$uid = $comment->uid;
if (empty($homepage)) {
if ($uid > 0 && user_access('access user profiles')) {
return l($name, 'user/' . $uid);
}
else {
return $name;
}
}
else {
return l($name, $homepage);
}