Steve Grunwell

Open-source contributor, speaker, and electronics tinkerer

Quick Tip: Set the Default Display Name for WordPress Users

I started work on a new WordPress site this morning and, after creating a couple of users, quickly got bored manually setting each user’s nickname and display_name properties in order to display authors as “firstname lastname.” I found a few forum posts in the WordPress support forums for “how do I automatically set the display name for WordPress users?” that had partial answers but no real solutions. Then I stumbled on this article by Rares Cosma that had just what I needed.

Rares’ solution uses the user_register WordPress action hook, which gets triggered when a new user account is registered. I modified his original version, streamlined it a bit, and applied the ‘firstname lastname’ pattern to both the display name and the nickname attribute:

Resources

Previous

Using Git Checksums to Invalidate Browser Caches

Next

Keeping WordPress Under [Version] Control with Git

11 Comments

  1. Ibrahim

    Is it sheer luck or just plain co-incidence that I was looking for a solution to this exact problem and have provide it just at the right time!!! :D

    I didn’t want to modify the core wp files. Thanks heaps! :)

  2. You can also use the pre_user_display_name hook to set the display name on registration. Explained here: http://geektamin.com/blog/533/why-update_user_meta-display_name-doesnt-work-and-how-to-use-pre_user_display_name-instead/

  3. H V S Krishna Kanth

    Where should I add this function?

  4. Here’s code to set the display name to “firstname lastname” and allow the WooCommerce customer to update it: https://github.com/woocommerce/woocommerce/issues/16015#issuecomment-338519085

  5. joemick14

    I am using a purchased theme in Word Press that has en error where the byline on an article or blog post displays the Word Press ID name rather than the “Display name publicly as” field. Could someone instruct me on how to add additional CSS code to that section to overwrite this error and display the Display Name rather than the WP ID? Much appreciated!!

    • It’s unlikely that CSS is going to fix your problem, here. The template tag used to echo the byline — typically the_author() — appears to have been replaced with something like the_author_ID() (which would show the author ID instead of the author’s display name).

      I’d recommend reaching out to the theme author and seeing if they offer support, but without knowing which theme or the domain, generic advice is about all I can offer.

  6. Alex

    Hey. Is this still functional? I’ve tried the code several times but it won’t work.

  7. Where should I add this function?please tell me

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Be excellent to each other.