Support » Fixing WordPress » How To? Set default display name to JUST the first name

  • Resolved sharris203


    Instead of the default display name being first AND last, how can I set it to just first (and/or their nickname)?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Go to admin – users and choose “edit” below the user name. Once there, find “Display name publicly as” and choose whatever name you want to be displayed.

    I don’t want to change everyone’s name manually. I want to change some internal code so it changes the default setting.

    The way my site is set, they enter their first & last name during sign up. If they immediately post a comment, it shows their first and last name. I’d like this to just show their first name. Or even better, show a generic name that I specify (until they actually go in their profile and change it)

    Here is code for a plugin that will put a generic name in the display name for ALL new users.

    Create a folder like this: wp-content/plugins/substitute_displayname

    Create a new file in that folder called substitute_displayname.php

    Paste the code below into that file.

    Activate the plugin.

    Plugin Name: Substitute Displayname
    Version: 0.1
    Description: Substitutes a default Display name for new registrants.
    Author: Mac McDonald
    /* Version check */
    global $wp_version;
    $exit_msg='Substitute Author requires WordPress 2.5 or newer.  <a href="">Please update!</a>';
    if (version_compare($wp_version,"2.5","<")) {
       exit ($exit_msg);
    function sd_new_login_filter ($login) {
    /* Don't do anything to login, just see if already in database.*/
       global $wpdb, $sd_is_new_login;
       $id = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$login'");
       $sd_is_new_login = (isset($id)) ? false : true;
       return $login;
    function sd_substitute_displayname_filter ($display_name) {
       global $sd_is_new_login;
       if ($sd_is_new_login) $display_name = 'New Author';
       return $display_name;
    add_filter('pre_user_login', 'sd_new_login_filter');
    add_filter('pre_user_display_name', 'sd_substitute_displayname_filter');

    Plugin worked great, thanks a lot

    You are very welcome! Thanks for the feedback.

    How can I change text ‘New Author’ in this plugin to any variable from registrations form? For example to $first_name only?

    Hi… I want new users by default to be given a public_display name set as their first_name and last_name rather than their username. The plug in above doesn’t quite do that. It set the public display name to “New Author”.

    How do I modify it to set the public display name to First & Last name?

    @dimmt, @millsd61

    This plugin cannot do what you want because the other fields are not available to it. It can only set the display name to a constant value.

    For those of you that want to switch the default to “First Name” or “Last Name” or both, add your thoughts to this thread here:

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How To? Set default display name to JUST the first name’ is closed to new replies.