• Resolved lindagester

    (@lindagester)


    How do I set the display name as first and last name without having to add the field “Display Name”?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @lindagester,

    There is no such feature currently.
    If you are comfortable using the code, you can use add the following code in function.php file of your current theme.

    function user_registration_modify_display_name( $form_data, $form_id, $user_id ) {
    
    	$display_name = '';
    	if ( isset( $form_data['first_name'] ) ) {
    		$display_name .= $form_data['first_name']->value;
    	}
    
    	if ( isset( $form_data['last_name'] ) ) {
    		$display_name .= ' ' . $form_data['last_name']->value;
    	}
    	$userdata = array(
    		'ID'           => $user_id,
    		'display_name' => $display_name,
    	);
    	wp_update_user( $userdata );
    }
    
    add_action( 'user_registration_after_register_user_action', 'user_registration_modify_display_name', 9, 3 );
    

    Thanks & Regards.

    Thread Starter lindagester

    (@lindagester)

    That worked like a charm, thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Set first and last name as display name’ is closed to new replies.