Andy Tran

How to display logged in username on the top right of your wordpress website

by | 13 Aug, 2020 | Wordpress | 1 comment

Display Logged in Username on Top Right of WordPress Website

Display Logged in Username

Today we will see how to display the currently logged-in username on the right side of the page.

Why Do We need to display the logged in username ?

Some time for some purpose we need to display username, so if multiple users are login from single browser or system they can easily navigate to their data. WordPress makes it really easy to get login user information. In this article we will show you how to get information about a currently logged-in user.

Write the following code in your functions.php file to get the current user name with a shortcode.

  • Login to your WordPress Admin Dashboard.
  • Now from the left sidebar go to Appearance -> Theme Editor.

display logged in username appearance

  • From the right-side panel, select functions.php file and write the below code snippet at the end of the file just before the closing PHP tag(?>)

logged in username function image code

Call Username on the header

  • Now with the help of Shortcode [current_user], you can display current username wherever you want on the website.
  • As we want to display the current username on the right top of the header, let us call this shortcode from our header.php file.
  • Please select the header.php file from the right-side panel of your Theme Editor page and write the below code snippet to display the username on the header.

Display logged in username

Position the Name to right

  • Give a unique identifier name as shown in the above picture.
  • Now go to Theme customizer from Appearance -> Customizer from the left sidebar

navigate to theme customizer from appearance

  • Now open Additional CSS tab</li
    </ul

customization of additional CSS tab

  • Now add the below code snippet to position username on the right side of your header

position username on the right

  • Add more CSS styles based on your requirement of positioning username on your website.

We hope this blog will help you to retrieve current username. For any please do comment in our comment section.

Check the developer resources for wp_get_current_user function here.

Are you looking for a top IT consulting and services company specializing in Salesforce consulting, mobile app development, and web application development? Look no further than Erudite Works Private Limited. We are a trusted technology and engineering consultancy offering advanced solutions to clients in various industries. Join millions of satisfied users and partner with us today! Contact Us.

Share this article...

1 Comment

  1. www.xmc.pl

    An impressive share, I simply given this onto a colleague who was doing a bit evaluation on this. And he the truth is purchased me breakfast as a result of I found it for him.. smile. So let me reword that: Thnx for the deal with! However yeah Thnkx for spending the time to debate this, I really feel strongly about it and love studying more on this topic. If attainable, as you turn into experience, would you mind updating your weblog with extra details? Its extremely helpful for me. Large thumb up for this blog put up!

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.