By default, WordPress sets a new member’s display name to their first and last name, or falls back to their username if no name is given. Depending on your membership site, you may want to display usernames for your members instead of their real names. This is common on community sites that use online personas.

If your site depends on usernames or you want to give your members a display name that keeps their identity private, you can use this code recipe to set each new member’s display name to match their username automatically at checkout.

Featured Image for Set the Member's Display Name to Username at Membership Checkout

Do You Need This Recipe?

This recipe is worth adding if:

  • Your community is built around usernames or handles instead of real names, such as gaming, hobby, or persona-driven memberships.
  • Members need privacy, and you do not want a real name showing up as their display name.
  • You want a consistent, predictable display name for every member without relying on what they type into the name fields at checkout.

Best Practices and Considerations

This recipe only affects new members created after you add it. It does not change the display name for members who already have an account. If you need to update existing members too, you will need to update display names manually or have a developer run a one-time script.

Keep in mind that a member’s display name is not private. It can appear in comments, author bylines, and BuddyPress or bbPress profiles if you use those plugins. Confirm that showing usernames publicly fits how your site’s members interact with each other before adding this recipe.

About the Code Recipe

The pmpro_checkout_new_user_array filter runs during checkout, right before PMPro creates a new WordPress user account for a member. It passes the $new_user_array array of user data that will be used to create that account.

The array includes standard WordPress user fields such as user_login (the username), user_emailuser_pass, and display_name.

This code recipe hooks into that filter to overwrite display_name with the value of user_login, so the account is created with the display name already set to match the username.

The Code Recipe

Adding the Recipe to Your Website

You can add this recipe to your site by creating a custom plugin or using the Code Snippets plugin available for free in the WordPress repository. Read this companion article for step-by-step directions on either method.

How to Customize This Code Recipe

Combine first and last name instead: If you collect a first and last name at checkout as required fields, and want to combine those fields to use as a display name, replace line 17 with $new_user_array['display_name'] = $new_user_array['first_name'] . ' ' . $new_user_array['last_name'];.



Was this article helpful?
YesNo

Free Course: Membership Site Development—The Basics

Develop a deeper understanding of membership site development in this beginner-level course. Learn how to make your site work better, save yourself time and money, and improve your site's performance.

Featured Image for Membership Site Development Course: The Basics