In this guide, we will cover how to display a user’s name in a WordPress menu. This will require a bit of knowledge with working with code snippets and general shortcodes in WordPress.
This solution will create a custom shortcode or variable, {{username}} to be inserted in any WordPress menu and then replace this variable with the user’s actual display name. This is great if you want to create a meta menu that points to a user’s profile page of some sort that says “Welcome admin“.
To add a custom code snippet to our WordPress site, without worrying about losing functionality in WordPress you may follow this guide.
Once the code snippet is added, it will replace the variable {{username}} with the user’s display name. To add this variable to your WordPress menu please take the following steps:
- Login to your WordPress dashboard.
- Navigate to Appearance and select Menus.
- Choose your menu you would like to add the username to.
- Find or add a menu item you would like to show the username in and click on the dropdown arrow.
- Edit the Link Text and add {{username}}
- Save your menu.
- Repeat this for each menu you would like to show the username in.
If you have any questions or feedback regarding this code snippet, please don’t hesitate to leave a comment below.
Photo by Adam Solomon on Unsplash | Code reference taken from (and altered): https://wordpress.stackexchange.com/questions/196453/displaying-logged-in-user-name-in-wordpress-menu