Display Logged in Username
Today we will see how to display currently logged in username on right side of page.
Why We need to display logged in username
Some time for some purpose we need to display username, so if multiple user 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.
- 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(?>)
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.
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
- Now open Additional CSS tab</li
- Now add the below code snippet to position username on the right side of your header
- 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 here for more WordPress blogs.
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!