Forum Replies Created

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • in reply to: Name instead of Username #88473
     nilje
    Participant

    GOT IT!

    this works

    COPY CODE
    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' => $name
      );
      wp_update_user( $args );
    }
    add_action( 'user_register', 'set_default_display_name' );
    in reply to: Name instead of Username #88461
     nilje
    Participant

    wow, that was easy. Really sorry, haven’t found this.

    what I just don’t get to work is the display name. So I have first and last name, but how will it take this for display name?
    here is a line to modify it, but it will always show the username, not the name which is set of first and last name

    COPY CODE
    //you can modify that line to change the displayed name to something else than the nickname
    	$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET display_name = %s WHERE ID = %d", $nickname, $user_id ) );

    I tried that:

    COPY CODE
    //you can modify that line to change the displayed name to something else than the nickname
    	$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET display_name = %s WHERE ID = %d", $firstname, $lastname, $user_id ) );

    thank you!!

Viewing 2 posts - 1 through 2 (of 2 total)

Log in with your credentials

Forgot your details?