Display the Name Instead of the Username in WordPress Posts

Display the Name Instead of the Username in WordPress Posts

A WordPress user has many handles. There is the username, the nickname, the first name, and the last name. The most common place to display one of these publicly is in the byline of each post just underneath the post title. Some themes choose to place it at the bottom instead. Most users never go into the settings to change their nicknames which by default are set to be the username. So if you leave things as they are, WordPress will display your username under the post title (depending on your theme). This is not ideal for a variety of reasons. To start off with, you might not want people to know your username as it will reduce the number of steps required to hack your account. Second, it might be something unappealing or un-indicative of your real name.

Let’s look at two ways to display the name instead of the username in WordPress. The first method will be a global setting that will affect most cases where your name is displayed. The second is a more fine-tuned approach that you can use to selectively choose what is shown where.

Global Display Name Change

The first step is to fill in the first name, last name, and the nickname in your user profile. Without this, WordPress will use your username as your nickname and display it like this:

nickname displayed

(In this test example, I’ve manually change my nickname something else so that it doesn’t display my username for security reasons. But if I hadn’t done that, it would show my login name instead).

Under the “Users” menu on the left hand side, click “Your Profile” to get to the settings screen. From here, scroll down to the “Name” subsection.

first name

Your username cannot be changed but you can fill in these three fields to let WordPress know that these are alternative handles. Just below that, there is another drop-down box called “Display name publicly as”.

public display name

This allows you to choose which one of the above you want WordPress to pull whenever necessary. In this example, I’ve chosen to use my first name. Once I save the changes and I refresh a post, you can see that it is now displayed instead of the previous handle:

first name displayed

This is a quick way to globally change your author name display settings. But what if you want to tweak it on a case-by-case basis? What if you want a nickname to be displayed in your author byline, but your full name to be displayed in the author box below every post? Luckily, WordPress provides a powerful set of functions that allow you to choose what to show when.

Using get_the_author_meta Instead

WordPress allows the get_the_author_meta to be used whenever you want to obtain specific information about a post author. Each user has quite a lot of metadata associated with them that is filled out in the user profile page or is implicitly determined. For example, you can get that e-mail, their role, their ID, and even out-of-the-way information such as the number of plug-ins they have displayed per page. The WordPress documentation on get_the_author_meta gives you a list of all the field names you can use to obtain various pieces of information.

So for example if you don’t want to change the global setting for username display, you simply need to find the place where the byline is generated depending on your theme. In the default Twenty Fourteen theme, this is the template-tags.php file. You need to locate the line containing “get_the_author”, comment it out and replace it with:

get_the_author_meta(‘first_name’)

Like in this screenshot here:

change code

This change will always display the first name regardless of the settings you choose in the drop-down box in the user profile screen. It provides WordPress developers with the ability to fine-tune the display name depending on the location.

If you’re simply looking for a global way to display the name instead of the username in WordPress, you should choose the first method. But if you need an alternative way to change just one occurrence, you should use get_the_author_meta instead.

Leave a Reply

This Website is Hosted by

Powered by RamNode

Disclosure: We receive a compensation from some of the companies whose products or services are presented on our website.