How to Make Admin Comments Become Authors in WordPress?

How to Make Admin Comments Become Authors in WordPress?

If you’re a WordPress administrator, you should hide your 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 a 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 this process in WordPress. You can’t change ownership of a comment. 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 customizing a filter. You don’t have to be logged in as the author to add/reply comments.

Make Admin Comments Become Author Comments

WordPress core have a filter called preprocess_comment to make admin comments become authors. You have to add this function on your theme’s functions.php, own plugin or functionality plugin.

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

In the above snippet, you can change the following things –

  1. Change 1 to the admin user id which you want to hide.
  2. Change 55 to the new author user id.
  3. Change Author Name with the 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 address.

If you have finished up with the change, your problem should be gone. Now try to add/reply a new comment from the administrator account, you will see the change immediately.

From now on, all admin comments will become the author comments. It will decrease the risk that hackers will gain access to your admin username. Please comment if you need further help.

Leave a Reply

Your email address will not be published. Your comments must follow our guidelines.