I want to display the commenters username or login name in a comment template. I know there is a function comment_author_link()
, but this displays the "display name publicly as" name and not necessarily the username. Usernames have to be unique so I would prefer to display the username. I have tried some other functions and have been looking all over for this. The closest I got was the following function:
<?php
if ($comment->user_id) {
$user=get_userdata($comment->user_id);
echo $user->user_login;
}
else {
comment_author_link();
}
?>
But for some reason this only displayed the name for the first commenter and then it does not display a name.
How do I display the commenters username or login name?
Thank you.
user_login
anduser_displayname
. :)