# Require a First and Last Name in Profiles

> Stops users from saving their profile (or an administrator from saving a user) without a first and last name.

- Type: PHP
- Runs: Admin only
- Category: [Users](https://wpide.com/library/category/users/)
- Tags: users, profile, validation
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/require-full-name-in-profile/

## Code

```php
add_action( 'user_profile_update_errors', function ( $errors, $update ) {
    if ( ! isset( $_POST['first_name'], $_POST['last_name'] ) ) {
        return;
    }

    if ( '' === trim( sanitize_text_field( wp_unslash( $_POST['first_name'] ) ) ) ) {
        $errors->add( 'wpide_first_name', '<strong>Error:</strong> Please enter a first name.', array( 'form-field' => 'first_name' ) );
    }

    if ( '' === trim( sanitize_text_field( wp_unslash( $_POST['last_name'] ) ) ) ) {
        $errors->add( 'wpide_last_name', '<strong>Error:</strong> Please enter a last name.', array( 'form-field' => 'last_name' ) );
    }
}, 10, 2 );
```

## Notes

Applies to the profile screens in wp-admin; existing users are only asked when they next save their profile.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Require a First and Last Name in Profiles" 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/
