Hide Author username in WordPress

WordPress is a very powerful blog publishing platform and cms. It is out of the box highly secure, however nothing is secure 100% and when you customize it according to your preferences manually or by plugins, your wordpress installation is likely to have security holes. When someone thinks about security of wordpress, the most fundamental thought is to change default username and create secure passwords. Some security plugins also do this as a first step towards a secure wordpress installation.

When someone brute forces your login credentials, it make attacks and chances of success 50% easier if the attacker knows your username. So hiding your wordpress login name or username is a good idea. In this article I will explain you how to change your author username in wordpress without any plugin or editing database manually.

How to hide username?

When you create a user in wordpress, the nickname also becomes same as username which is displayed publicly. So basically your nickname exposes the username to pubic if it is same as username because nickname is shown in all author posts and archive pages. Nickname is saved as user_nicename in wordpress installation database.

The trick is to change your nicename or username from wp users table to make them different. There are many articles that explain this. Some wordpress security plugins also allow you to do this. For this I recommend you iThemes Security.

Or if you don’t want to use a plugin then you can use the following given code. Go to your theme’s functions.php (or in child theme’s functions.php if you use child themes) file and add the following code to it. This will force users to choose their nicknames different from usernames. After adding this, go to your profile from wordpress admin and change nickname and then click save. Also change your name from “show name publicly as” option.

Note that you will only need to change nicknames of existing users. This function will automatically change them for all future users.

hide username in wordpress

/*=== this function will force users to choose unique nicknames ======*/
function force_unique_nickname( &$errors, $update, &$user ) {

	$display_name = isset( $user->display_name ) ? $user->display_name : substr( str_shuffle( "abcdefghijklmnopqrstuvwxyz" ), mt_rand( 0, 14 ), 12 );

	if ( ! empty( $user->nickname ) ) {

		if ( $user->nickname == $user->user_login ) {

			$errors->add( 'user_error', __( 'Your Nickname must be different from your login name. Please choose a different Nickname.' ) );

		} else {

			$user->user_nicename = sanitize_title( $user->nickname, $display_name );

		}

	} elseif ( ! empty( $user->first_name ) && ! empty( $user->last_name ) ) {

		$full_name = $user->first_name . ' ' . $user->last_name;

		$user->nickname = $full_name;

		$user->user_nicename = sanitize_title( $full_name, $display_name );

	} else {

		$errors->add( 'user_error', __( 'A Nickname is required. Please choose a nickname.' ) );

	}

}

add_action( 'user_profile_update_errors', 'force_unique_nickname' , 10, 3 );
/*===================================*/

Note that this code is adapted from iThemes-security. So if you are using iThemes security then you don’t need to add this code.

About Asim

View all Posts

Asim is a blogger who enjoys writing articles on Technology and Blogging niche. He is our Gold Star Contributor.