How to Make Admin Comments Become Authors in WordPress?

Categories WordPress TutorialsTags , , , Start discussion

If you’re a WordPress administrator, you should hide your admin username. This is the best security practice not to allow anyone to steal admin username. WordPress assign admin posts/pages and comments with an HTML class. That’s why you shouldn’t publish posts/pages and admin comments under admin account. It increases the risk that hackers will gain admin access by username.

You should create different user account with author capability to make admin posts/pages as the author posts/pages. And then you can easily publish posts/pages without logged in as the author account. You can write post/pages while logged in under admin account and can select your created author as the posts/pages author. No one will know your admin username after you published as different username.

But, you can’t make admin comments as an author comments by default settings of WordPress. Its not easy as the previous one. You have to be logged in as that author to add/reply comments as the author. It’s really annoying and confusing continuously using two browsers, switching accounts for different purpose.

Annoying & Confusing - Make Admin Comments Author

Not annoying anymore! There is a solution for that. You can make your admin comments become author comments by a custom function. You don’t have to be logged in as the author to add/reply comments. WordPress core have a filter called preprocess_comment to extend functionality.

Make Admin Comments Become Author Comments

You have add this function in themes functions.php, your own plugin or Functionality plugin. We recommend to use the function in functionality plugin.

// Make admin comments become author comments
function sm_admin_comments_to_author_comments( $comment_data ) {
    if ( $comment_data['user_ID'] == 1 ) { 
        $comment_data['user_ID'] = 15;
        $comment_data['comment_author'] = 'Author Name';
        $comment_data['comment_author_email'] = 'AuthorMail@example.com';
        $comment_data['comment_author_url'] = 'AuthorWebsite.com';      
    }
    return $comment_data;
}
add_filter( 'preprocess_comment', 'sm_admin_comments_to_author_comments' );

In this code, you have to change the following things –

  1. Change 1 to your admin id (which user you want to hide)
  2. Change 15 to your author id (new comment holder id)
  3. Change Author Name with new comment holder name
  4. Change author@example.com with the email of the new comment holder
  5. And finally change example.com to new comment holder website URL

If you have changed the values to the correct one, you will find all problem solved. Now try to add/reply a new comment from administrator account, you will see the change immediately. From now on, all admin comments will become the author comments – better security as you like!

Please comment if you need further help.

Leave a Reply

Your email address will not be published.