Skip Navigation

[Resolved] hide nickname and copy it from username

This thread is resolved. Here is a description of the problem and solution.

Problem:
The user would like to hide the nickname in a user form and automatically copy the email to the nickname.

Solution:
- Hide the nickname from the form options.
- Add the following code to copy the user email to the nickname:

/* update nickname field with the value of user_login. */
function my_copy_nickame_from_username( $user_id ) {
  $user = get_user_by( 'id', $user_id);
  update_user_meta( $user_id, 'nickname', $user->user_login );
}
add_action( 'user_register', 'my_copy_nickame_from_username' );
This support ticket is created 3 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 2 replies, has 2 voices.

Last updated by WeiS2074 3 years, 10 months ago.

Assisted by: Jamal.

Author
Posts
#1660067

Great, I have followed the pattern and make a label. Another question, can I hide "nickname" on the front end, but when user enter "username" it automatically copies "username" into "nickname". How do I make this approach?

#1660149

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

To hide the nickname, I would suggest removing the field from the form. Switch to expert mode and remove the field.

There is an option to auto-generate the nickname, check this screenshot.

If you need to copy the username to the nickname, you will have to use custom code on your theme's functions.php, a new plugin, or in Toolset->Settings->Custom code(tab).

/* update nickname field with the value of user_login. */
function my_copy_nickame_from_username( $user_id ) {
  $user = get_user_by( 'id', $user_id);
  update_user_meta( $user_id, 'nickname', $user->user_login );
}
add_action( 'user_register', 'my_copy_nickame_from_username' );
#1660205

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.