WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way I can force all users display names to be Firstname Lastname or alternatively change this to be the default?

share|improve this question

This is set during user registration. You can change the value per filter 'user_register'.

Sample code, not tested:

/* Plugin Name: First name plus last name as default display name. */
add_action( 'user_register', 'wpse_67444_first_last_display_name' );

function wpse_67444_first_last_display_name( $user_id )
    $data = get_userdata( $user_id );
    // check if these data are available in your real code!
        array (
            'ID' => $user_id, 
            'display_name' => "$data->first_name $data->last_name"
share|improve this answer
Added to functions.php? Also, is the wpse_67444 part important? – Svish Oct 7 '12 at 23:05
I would put it into a separate plugin. The prefix is just a convention on our site to avoid collisions with other code. – toscho Oct 7 '12 at 23:24
WordPress newb here, hehe. How would you put it in a separate plugin? Is it just a matter of putting it in a certain file in a certain folder or something?` – Svish Oct 8 '12 at 17:49
@Svish See my edit. Put the code into a separate file and move it to your plugin directory. Then activate it – done. – toscho Oct 8 '12 at 17:53
$data = get_userdata( $userid ); should be $data = get_userdata( $user_id ); – loQ Jul 6 at 3:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.