Skip to:

How to auto generate username from first and last name?

  • Profile photo of viniciusb
    Vinnie Barbarino


    I’m trying to create a registration page with ‘first name’, ‘last name’, ’email’ and ‘password’, without the need for the user to create a username.

    The username would be autogenerated off of the user’s first and last name. E.g. If user’s name is John Doe, his username would be automatic created as ‘john_doe’.

    If another user registered with that same name, username “john_doe_1” would be created – as WP does with images.

    I know this is possible because that is how “Login/Register with FB plugins” do.

    A plugin that did that would be ideal, but I couldn’t find anything.

Viewing 1 replies (of 1 total)
  • Profile photo of Henry Wright
    Henry Wright


    Just do something like this: $username = $first . '_' . $last;

    If you need to check a username exists, you can do: if ( username_exists( $username ) )

Viewing 1 replies (of 1 total)
  • The topic ‘How to auto generate username from first and last name?’ is closed to new replies.
Skip to toolbar