0

I wondered if anyone has a solution for the following scenario i would like to force when a user registers Display name publicly to Nickname by default instead of first name and last name which is what is set by default in WP.

Many thanks in advance JM

3
  • one addition to the question the objective is that when users generate posts written by field displays their nickname.
    – user160843
    Commented Feb 8, 2019 at 14:32
  • You can edit your question to include that note, but before you do, can you reword it? I don't understand what you mean by "written by field"
    – Tom J Nowell
    Commented Feb 8, 2019 at 14:40
  • I think they mean they want the byline on posts to use the author's nickname. Commented Feb 8, 2019 at 15:33

2 Answers 2

1

You can use the user_register hook, which is fired after the user is registered, to set the name to whatever you like:

function fix_user_display_name($user_id) {
    $user = get_user_by('id', $user_id);
    $display_name = $user->user_nicename;

    wp_update_user(array(
        'ID'           => $user_id,
        'display_name' => $display_name
    )) ;
}

add_action("user_register", "fix_user_display_name", 20);[1]
1
  • nicename is not the same as the nickname. Commented Feb 8, 2019 at 15:38
1

Hi Guys in response to further details on my answer, so basically i searched for plugin solutions in preference to adding code (i am not a developer) and found a plugin that does the job very well called change display name publicly as. Hope this feedback is relevant and helpful.

many thanks,

J

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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