How To Show The Logged Username In WordPress WooCommerce Website

Hello WordPress Devs,

Today we are going to see how to display a logged-in username in WordPress. It’s common that everyone is showing every woocommerce website showing “My Account” label for all logged-in users and this is an old way trend now. We have to update ourselves based on the trends. People like modern styles nowadays so we’ve to update our website designs based on the trends.

Currently, On every website logged in users see the My Account Label on the navigation menu like this image but this is a really old way to interact with users. So, that’s why we need to change our designs.

woocommerce my account label

woocommerce my account label

 

But today we are going to display a logged-in username instead of “My Account” and our customers will like it 100%.  I can assure you that if you implement these features on your website then it will make a great impression on the customers.

How to Show The Logged In Username in WordPress. There are many ways to Display the logged-in username but today we are going to see the easiest way to display the logged-in username in WordPress.

[embedyt] https://www.youtube.com/watch?v=Uq2bxrWLPlQ [/embedyt]

First of all, go to the appearance -> menu from the WordPress dashboard. After that make sure that you assign your label with “My Account” or “Any name” That you want to display for unregistered users.

Remember one thing, if your label is like this [My Account] then you have to add this name to your function. You cannot use a name like [My account] this. It’s case-sensitive.  Check our reference image first

 

After that from the WordPress dashboard go to Plugins -> Add New  and Search For Code Snippets Plugin

Code Snippets

Or you can download it from wordpress.org official website. Link below

Code Snippets

Once you download it then click on install and activate it. After that go code snippets menu from the WordPress dashboard and click on add new. Code Snippets -> Add New then you will see something like the below screenshot

code snippets add new snippets

 

Then Give a Title To Your Snippet and Add This code to your snippet code area like this below image

Show Logged In Username WordPress Code

Show Logged In Username WordPress Code

 

function wpcodersclub_label( $items, $args ){	if( is_user_logged_in() ){		$currentUser = wp_get_current_user();		$items = str_replace("My Account", $currentUser->display_name, $items);	} 		return "<p style='color:#fff; margin-top:5px'> Username: " .$items . "</p>";}add_filter('wp_nav_menu_items', 'wpcodersclub_label', 9999, 2);

After that click Save Changes and Activate 

 

Once you follow my instruction then go home page and you’ll see your Username: WP Coders Club like this in the navigation menu like below image

display woocommerce logged in username on wordpress

 

That’s it for now. Hope This will help you.

Post a Comment

0 Comments