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 substitute them with a few lines of code.

In this case study, I have added the “My Account” page to the navigation menu and renamed it to “ACCOUNT” in the menu settings. However, I want that label to change to “LOGIN” if the user is logged out. Enjoy!

When logged out, my own website navigation menu shows a “LOGIN” button. If logged in, the same menu link label changes to “ACCOUNT”.

PHP Snippet: Conditionally Rename “My Account” Menu Label If User Is Logged Out

 * @snippet       Rename "My Account" Link @ WooCommerce/WP Nav Menu
 * @how-to        Get FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 3.7
 * @donate $9

add_filter( 'wp_nav_menu_items', 'dynamic_label_change', 10, 2 ); 

function dynamic_label_change( $items, $args ) { 
	if ( ! is_user_logged_in() ) { 
		$items = str_replace( "My Account", "Login", $items ); 
	return $items; 

Leave a Reply