• Resolved rivistaro

    (@rivistaro)


    Hi there!

    Is there a way to set automatically the “display name” as “first name” when a new user registers in my web site?

    Thank you very much!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi,

    We can achieve this by using some custom code:

    1. Create an empty plugin like this: https://gist.github.com/sareiodata/76f701e01db6685829db

    2. Add the following code to the end of it:

    /*
     * Change the Display Name after Registration into First Name
     */
    
    add_action( 'user_register', 'wppbc_change_displayname_into_firstname' );
    
    function wppbc_change_displayname_into_firstname( $user_id )
    {
        $data = get_userdata( $user_id );
        // check if these data are available in your real code!
        wp_update_user(
            array (
                'ID' => $user_id,
                'display_name' => "$data->first_name"
            )
        );
    }

    3. Install this plugin via FTP (copy it inside wp-content/plugins) or create a zip archive with it and install it via the WordPress plugin upload functionality

    Test it out and let me know if it works.

    Best regards,

    Thread Starter rivistaro

    (@rivistaro)

    Hi Teodor!
    Thank you very much for your support.

    I tried to do as you told me, but unfortunatly don’t work ??

    How can I try to change?

    Thanks again!

    Hi,

    In order to debug this issue further please submit a support ticket.

    I will wait for your ticket and we will continue our conversation there.

    Best regards,

    Add this to your functions.php:

    add_action( 'user_register', 'my_profile_update', 10, 1 );
    function my_profile_update( $user_id ) {
    
       // Change Display Name
        $user = get_userdata( $user_id );
        $userdata = array(
            'ID' => $user->ID,
            'display_name' => $user->user_firstname,
        );
        wp_update_user( $userdata );
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Set “first name” as “display name” when a new user registers’ is closed to new replies.