You could install a free WordPress plugin to enable “LOGIN / LOGOUT” menu links – or you could use a super simple snippet. Once again, the less plugins you use the better, especially if you can replace them with a few lines of code.
In this case study, I have added the “My Account” page to the navigation menu and I want that label to change to “Login” if the user is logged out. Enjoy!

PHP Snippet: Conditionally Rename “My Account” Menu Label If User Is Logged Out
/**
* @snippet Rename "My Account" Link @ WooCommerce/WP Nav Menu
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @compatible WooCommerce 4.5
* @community https://businessbloomer.com/club/
*/
add_filter( 'wp_nav_menu_items', 'bbloomer_dynamic_menu_item_label', 9999, 2 );
function bbloomer_dynamic_menu_item_label( $items, $args ) {
if ( ! is_user_logged_in() ) {
$items = str_replace( "My Account", "Login", $items );
}
return $items;
}
Please note that if you rename the “navigation label” you must change the code accordingly:

PHP Snippet: Conditionally Rename Custom Menu Label If User Is Logged Out
/**
* @snippet Rename Custom Link Label @ WooCommerce/WP Nav Menu
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @compatible WooCommerce 4.5
* @community https://businessbloomer.com/club/
*/
add_filter( 'wp_nav_menu_items', 'bbloomer_dynamic_menu_item_label', 9999, 2 );
function bbloomer_dynamic_menu_item_label( $items, $args ) {
if ( ! is_user_logged_in() ) {
$items = str_replace( "Account", "Login", $items );
}
return $items;
}
Can confirm this still works. Make sure to use it exactly and that you are targeting the right item.
Cool
Thank you SO much! Worked beautifully in both, the primary and secondary menu. Of course, this was after I made sure everything was actually named THE SAME in both menus.
Nice!
How would you do this if you wanted it to say login is logged out ANS logout if logged in?
Not sure I follow?
Works great with woocommerce 6.2.0. Thanks for your enormous work Rodolfo!
Great!
Thanks for this, how would this need to be modified to work on a secondary menu (I’m using Divi).
Hi Chris! This should work on any WP menu, secondary included
Dear,
I used the exact same snippet as you suggested, but it seem to only work on the /my-account/ page and not on other pages such as the home page. Any idea on how I can resolve this?
Thank you in advance.
Regards,
Mathias
Hi Mathias, I use this on my own website. This is meant to work in your Navigation Menu
Hey, as of March 13 2021 this code, and actually all of the code I used from you doesnt work. The main reason is because of woocommerce’s 5.0.0 (or it could be 5.1.0, I’m no really sure which one is) update. Can you help everyone fixing this issue please?
ALL of my snippets don’t work? LOL, that’s pretty bad. Woo 5.0 wasn’t that big deal, so I’d be surprised. To troubleshoot, disable all plugins but WooCommerce and also switch temporarily to “Twentytwenty” theme (load the snippet there in functions.php) as explained here: https://www.businessbloomer.com/lesson/trwm4l01/
Once you do that, does it work? If yes, you have a problem with your current theme or one of the plugins.
Hope this helps!
Hi! Works fine on my website. Thank you for the tutorial. I just wanted to ask: how can I change the link of the login page? I have my own customized login page and I want to change it from the wordpress default page.
Hi, maybe from the WordPress menu?
Hi, the snippet works great. But does it also work on the My Account on the right side of the menu? The one that comes with the plugin?
No sorry this is for WordPress menus
Worked a treat for me (using PHP 7.4) .
Thank you!
Cool
I tried this on two different websites, they’re identical clones of one another, the only difference is that the one is on a higher version of php 7.4… and it’s not working
This is the error I get:
“The snippet has been deactivated due to an error on line 4:
Cannot redeclare function dynamic_label_change. “
Not sure, that’s not my function
Just tried it and it works great! No need for a plugin. Thank you very much!
Way to go!
Hello,
your code still work smoothly
do you have a tutorial ifsomeone login then the teks link will change to the name of the user instead of my-account
thank you
Hi Morgan, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
I just tried this, the exact snippet, but it’s not working for me.
Other snippets I found here are working perfectly. Any idea what the problem could be?
Read through the comments. This is case-sensitive, maybe https://businessbloomer.com/woocommerce-rename-my-account-menu-label-if-logged-out/#comment-355148 might help
It works flawlessly. Check the labels, if it is “My Account” or not. Those who are confused about label, it is the Page name or rather the Menu item name. It is case sensitive, if your account page is named something else, try using that instead of “My Account” in the snippet code. Stop blind copy paste, use your head guys.
TOP!
it didn’t work 🙁 . i follow every step on your tutorial.
This is case sensitive – try again?
Awesome snippet – worked perfectly (once I’d changed it from ‘My account’ to ‘My Account’ 😉 )
Thank you!
Great!
Hi Rodolfo,
I have the same problem. Did exactly as you teaching in your explanation video and used your exact snippet.
I use current version of WooCommerce: 3.8.0, and WP version is 5.3
Hi Sagi. Do you have a “My Account” navigation menu link (because I do and the snippet works on this same website)?
Hi, just tried it out and nope, it didn’t work.
Did you use my exact snippet?