Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm creating a simple directory from the user accounts and want to simplify it as much as possible for the users. I changed the label on nickname to Lastname, Firstname so that the users can be alphabetized by the nickname field, but I want the display_name to default, or even force, to the nickname field. I haven't seen a plugin, so I'm looking for something I can add to the functions to do this. Any ideas?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

You can force this with a hook that activates when the profile is updated. The next step would be to hide the display_name select box, you can do that with some Javascript.

add_action( 'user_profile_update_errors', 'wpse7352_set_user_display_name_to_nickname', 10, 3 );
function wpse7352_set_user_display_name_to_nickname( &$errors, $update, &$user )
{
    if ( ! empty( $user->nickname ) ) {
        $user->display_name = $user->nickname;
    }
}
share|improve this answer
add comment

Your Answer

 
discard

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.