Validate Duplicate Display Name with WP User Frontend

WP User Frontend is a form builder which let you create custom post and registration form. It has plenty of custom fields available for both post form and registration form, you may already know that.

I”ll not discouss about the features of WP User Frontend here, rather you can find it here.

WPUF- is the short form of WP User Frontend and I’m going to use this rest of my post.

However, with the WPUF ‘username’ filed, you can validate the duplicate username of your site. Like: someone used ‘John’ as a username while registering but someone already has registered with this name. So, it will validate the name and provide a notice to the user that someone already taken this name, you need to choose any other name.

How to validate display name in WordPress registration

That’s all good! but what if you like to validate the Display name as well? The default Display Name field of WPUF doesn’t offer to validate. Actually, most of the cases, it doesn’t require to validate the Display name as Display name can be the same for several users, it doesn’t really matter.

See also  How to hide Dokan News Update on the dashboard

Some days ago, one of our WPUF users needed this and we came with a solution for this. Actually, I was taking care of him but he created the snippet his own and shared with me to provide it to the people, if someone needs in the future. Kuddus to #Chris Arnold

Here is the snippet he used and shred with me:

// CUSTOM -- if any display name given, check if it exists

if ( $this->search( $user_vars, 'name', 'display_name' )) {

$display_name = sanitize_user( trim( $_POST['display_name'] ) );

global $wpdb;

$query_cnt = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM $wpdb->users WHERE display_name = %s", $display_name ) );

if ( $query_cnt == 1 ) {

$this->send_error( __( 'Sorry, Display Name is already in use. It needs to be unique.', 'wpuf-pro' ) );



Use this snippet on your function.php file. The Display name should validate now on the WPUF registration form 🙂

Validate display name WordPress registration

One Comments

Leave a Reply