How to add a user role label next to comments in WordPress?

Blog post comments are a fantastic way to interact with your readers. But your comments and those of your editorial team can be given additional weight by identifying as “official” responses from your website. One way to do this is to label those comments with the WordPress user role – “Admin”, “Editor”, “Author” and so on.

Use the following steps to add a user role label next to comments in WordPress.

Adding the role label requires us to edit the WordPress theme’s functions.php file, which we can do using cPanel File Manager.

Log into the HostPapa dashboard and visit My cPanel. Head to Files > cPanel File Manager to view the files and folders stored on your server.

Navigate to your WordPress folder then enter the wp-content > themes folder. Open the folder for your current theme, then select functions.php and click Edit in the command bar.

Scroll to the bottom of the page, and enter the following code:

* Add User Role to Comments.
if ( ! class_exists( 'Comment_Author_Role_Label' ) ) :
class Comment_Author_Role_Label {
public function __construct() {
add_filter( 'get_comment_author', array( $this, 'get_comment_author_role' ), 10, 3 );
add_filter( 'get_comment_author_link', array( $this, 'comment_author_role' ) );
function get_comment_author_role($author, $comment_id, $comment) {
$authoremail = get_comment_author_email( $comment);
if (email_exists($authoremail)) {
$commet_user_role = get_user_by( 'email', $authoremail );
$comment_user_role = $commet_user_role->roles[0];
$this->comment_user_role = ' ' . ucfirst($comment_user_role) . '';
} else {
$this->comment_user_role = '';
return $author;
function comment_author_role($author) {
return $author .= $this->comment_user_role;
new Comment_Author_Role_Label;

 Save the file and close cPanel File Manager.

Now visit your site’s front end and review comments you’ve made on posts. You should see your user role displayed next to your name.

  • How to add a user role label next to comments in WordPress
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to manage polls in Joomla?

  Putting the poll will help your site visitors to vote on the specific multiple choice...

How to manage web links in Joomla?

You need to go to the components tab and then to the Web Links. And then you have to click on...

Increasing PHP Memory Limit for WordPress

To set the maximum amount of memory that can be used by PHP for WordPress blog, follow these...

Installation of Joomla with Fantastico and Softaculous

Joomla can be installed easily and quickly by Fantastico or Softaculous which are offered with...

Installation of WordPress with Fantastico and Softaculous

WordPress can be installed quickly and easily through Systems installation with 1-click...