WooCommerce is the most popular ecommerce plugin in the WordPress ecosystem. However, it has a bit of a nagging usability issue. By default, WooCommerce doesn’t show if a user is logged in or not to your ecommerce site.


Add a Woocommerce login logout link to the Woocommerce menu

At times, this can be confusing to your customers. Since most of the popular ecommerce stores (say ebay or Amazon) show a Login button in their menu, customers may expect the same in your e-commerce stores too.

However, in the case of a WooCommerce powered store, a user will need to visit the ‘my account’ page to create an account or check whether he is logged in or not.

woocommerce my account - logout link

In this tutorial, we’ll explain how to add Login/Logout option to the top menu of your WooCommerce website store. This is one of the more popular tips and tricks by CollectiveRay.com - so stay tuned if you want to learn more tips and tricks!

Create a Top Primary Menu

Step 1: Before proceeding any further, make sure you have added a menu as a primary menu of your theme. Also make sure you have made a full Wordpress backup in case something goes wrong

If you have not added a menu as a primary menu, log in to your WordPress admin, go to Appearance >> Menu. Under the Menu Settings create a menu and check the “Top primary menu” box.

woocommerce menu

Top tip: If you're not comfortable doing code changes, you might want to consider hiring a WordPress developer. Click here to learn how to hire the ideal WordPress developer: https://www.collectiveray.com/wordpress-developers-for-hire

Step 2: Add the below code to your functions.php file of your theme.

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

function add_loginout_link( $items, $args ) {

  if (is_user_logged_in() && $args->theme_location == 'primary') {

   $items .= '<li><a href="'. wp_logout_url( get_permalink( wc_get_page_id( 'myaccount' ) ) ) .'">Log Out</a></li>';


  elseif (!is_user_logged_in() && $args->theme_location == 'primary') {

   $items .= '<li><a href="' . get_permalink( wc_get_page_id( 'myaccount' ) ) . '">Log In</a></li>';


  return $items;


UPDATE: We have just been adviced by a helpful reader/commentor of the website who said that wc_get_page_id should now be used instead of the (now deprecated) woocommerce_get_page_id

Verify the Woocommerce login / logout link

Once you've changed the functions.php to add the Woocommerce login / logout links, it's time to result the result of your changes. If you have done the changes correctly, you'll see the result below.

woocommerce login / logout links

You’re done! Now you can see that the Login/Logout option is being displayed in the top menu of your store. This trick is especially useful if you have set up a subscription box based business which we've detailed here.

Now that we've shown you how to do this for WooCommerce, maybe it's time to do the same thing and create a WordPress Logout link. This is often the case if you have decided to disable the admin bar, but still would like the option to sign out, just to be on the safe side.

If you are just looking for a way to end your logged in sessions, simply visit the following on your website.


You will get a small confirmation screen asking "Do you really want to log out?" - once you click on the link, you will be signed out.

WordPress logout screen

As always there are multiple ways to do this. 

The WordPress Logout URL is something you can actually use in your menu, if you want to create a WordPress logout button. Simply link the URL above, and of course, this will allow your user to terminate any current sessions.

Logout menu


If this does not work for some reason, you might need to tweak your functions.php to enable this functionality. 

add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
function add_login_logout_link($items, $args) {
   $loginoutlink = ob_get_contents();
   $items .= '<li>'. $loginoutlink .'</li>';
   return $items;


Note: this above method works and is enabled if you are using WordPress custom menus i.e.  the menu function available in the admin section under Appearance > Menus.)

WordPress Logout Shortcode

Just like with most functions, you'll find that there is also a plugin that can be used to generate a WordPress Logout Shortcode. Besides the various configurations you can perform, this plugin gives you the ability to use the following shortcodes within your posts and pages.

[logout] - A standard Log Out link, where the user stays on the login screen after being logged out.
[logout_to_home] - A link that logs the user out, and redirects them to your home page.
[logout_to_current] - A link that logs the user out, and redirects them back to the current page/URL.

The plugin also has various options to configure the look and feel and texts, or the actual user experience.

Anything else you'd like to know about logging out

Is there anything that you'd like to know and is missing is this article? We'd love to get your comments so we can keep making this post better!  

Download the list of 101 WordPress tricks every blogger should know

101 WordPress tricks

Click here to Download Now
About the Author
David Attard
Author: David AttardWebsite: https://www.linkedin.com/in/dattard/
David has been working in or around the online / digital industry for the last 18 years. He has vast experience in the software and web design industries using WordPress, Joomla and niches surrounding them. As a digital consultant, his focus is on helping businesses get a competitive advantage using a combination of their website and digital platforms available today.

One more thing... Did you know that people who share useful stuff like this post look AWESOME too? ;-)
Please leave a useful comment with your thoughts, then share this on your Facebook group(s) who would find this useful and let's reap the benefits together. Thank you for sharing and being nice!

Disclosure: This page may contain links to external sites for products which we love and wholeheartedly recommend. If you buy products we suggest, we may earn a referral fee. Such fees do not influence our recommendations and we do not accept payments for positive reviews.

Featured On

Inc Magazine Logo  

Sitepoint logo  

CSS Tricks logo   

webdesignerdepot logo   WPMU DEV logo   

and many more!



Get Started Now With ShutterstockShutterstock

Best Rated Caching Plugin

Make your website faster 

How to make your website FAST!

Step-by-step - free email course, how to make your website load in less than 1 second  

who are we?

CollectiveRay is run by David Attard - working in and around the web design niche for more than 12 years, we provide actionable tips for people who work with and on websites. We also run DronesBuy.net - a website for drone hobbyists.

David attard