Updates, Tips & Tricks

Updates as Released, Plus My Personal Collection Of WordPress Best Practices

Change the Default WordPress Display Name

05 April

When a new user registers, you can change the default population of the Display Name and make it, e.g., Firstname Lastname. Here’s a snippet you can add to your functions.php:

// Set Display Name to Firstname Lastname
function set_default_display_name( $user_id ) {
  $user = get_userdata( $user_id );
  $name = sprintf( '%s %s', $user->first_name, $user->last_name );
  $args = array(
    'ID' => $user_id,
    'display_name' => $name,
    'nickname' => $user->first_name
  );
  wp_update_user( $args );
}
add_action( 'user_register', 'set_default_display_name' );
No comments yet.

Leave a Reply