Get the Current username
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.