WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How To? Set default display name to JUST the first name (10 posts)

  1. sharris203
    Member
    Posted 4 years ago #

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

  2. llizard
    Member
    Posted 4 years ago #

    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.

  3. sharris203
    Member
    Posted 4 years ago #

    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)

  4. vtxyzzy
    Member
    Posted 4 years ago #

    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.

    <?php
    /*
    Plugin Name: Substitute Displayname
    Version: 0.1
    Description: Substitutes a default Display name for new registrants.
    Author: Mac McDonald
    */
    ?>
    <?php
    /* Version check */
    global $wp_version;
    $exit_msg='Substitute Author requires WordPress 2.5 or newer.  <a href="http://codex.wordpress.org/Upgrading_WordPress">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');
    ?>
  5. sharris203
    Member
    Posted 4 years ago #

    Plugin worked great, thanks a lot

  6. vtxyzzy
    Member
    Posted 4 years ago #

    You are very welcome! Thanks for the feedback.

  7. dimmt
    Member
    Posted 4 years ago #

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

  8. millsd61
    Member
    Posted 4 years ago #

    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?

  9. vtxyzzy
    Member
    Posted 4 years ago #

    @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.

  10. Tevya
    Member
    Posted 3 years ago #

    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: http://wordpress.org/support/topic/change-default-display-name-1

Topic Closed

This topic has been closed to new replies.

About this Topic