admin管理员组

文章数量:1330564

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

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

Share Improve this question asked Feb 8, 2019 at 14:30 user160843user160843 111 silver badge2 bronze badges 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. – Jacob Peattie Commented Feb 8, 2019 at 15:33
Add a comment  | 

2 Answers 2

Reset to default 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]

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

本文标签: user registrationForce display name to nickname wp