# Never Show Login Names as Public Display Names

> When a user's public display name is the same as their login name (the WordPress default), switches it to their first and last name, or to a neutral name, so author bylines and comments do not reveal usernames.

- Type: PHP
- Runs: Run everywhere
- Category: [Security](https://wpide.com/library/category/security/)
- Tags: user-enumeration, users, authors
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/sec-display-name-not-username/

## Code

```php
add_filter( 'wp_pre_insert_user_data', function ( $data, $update, $user_id, $userdata ) {
    if ( empty( $data['user_login'] ) || empty( $data['display_name'] ) || strtolower( $data['display_name'] ) !== strtolower( $data['user_login'] ) ) {
        return $data;
    }

    $first = isset( $userdata['first_name'] ) ? trim( (string) $userdata['first_name'] ) : '';
    $last  = isset( $userdata['last_name'] ) ? trim( (string) $userdata['last_name'] ) : '';

    if ( $user_id && ! $first && ! $last ) {
        $first = (string) get_user_meta( $user_id, 'first_name', true );
        $last  = (string) get_user_meta( $user_id, 'last_name', true );
    }

    $name = trim( $first . ' ' . $last );

    $data['display_name'] = '' !== $name ? $name : 'Member ' . strtoupper( substr( md5( $data['user_login'] . wp_salt() ), 0, 5 ) );

    return $data;
}, 10, 4 );
```

## Notes

Applies when accounts are created or updated; existing accounts change the next time they are saved.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Never Show Login Names as Public 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/
