# Require Unique Display Names

> Stops users from picking a public display name that another member already uses, which prevents impersonation in comments and forums.

- Type: PHP
- Runs: Run everywhere
- Category: [Users](https://wpide.com/library/category/users/)
- Tags: profile, users, security
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/unique-display-names/

## Code

```php
add_action( 'user_profile_update_errors', function ( $errors, $update, $user ) {
    if ( empty( $user->display_name ) ) {
        return;
    }

    global $wpdb;

    $taken = $wpdb->get_var( $wpdb->prepare(
        "SELECT ID FROM {$wpdb->users} WHERE display_name = %s AND ID != %d LIMIT 1",
        $user->display_name,
        isset( $user->ID ) ? (int) $user->ID : 0
    ) );

    if ( $taken ) {
        $errors->add( 'wpide_display_name_taken', '<strong>Error:</strong> That display name is already used by another member. Please choose a different one.' );
    }
}, 10, 3 );
```

## Notes

Checked when profiles are saved in wp-admin; existing duplicates are left alone until those users next save their profile.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Require Unique Display Names" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
