Add WooCommerce MyAccount Page Login/Logout to Menu

This code adds a login/logout link to your WordPress primary menu to log the user into the WooCommerce My Account page and then also log out to the same or different page.

It differs from the referred article as that adds the WordPress default login/logout page.

The menus need to be registered via register_nav_menu and positioned with theme_location, so the trick is to find the registered menu name. You can find this in the dashboard on the menus page – then inspect with browser dev tools to see what it is.

Menu Location Dashboard

Dashboard Menus Page


Menu Location Menu Name

See Menu Name in Code


So in the above example, the name to use would be header



  1. Ivana Murray on April 7, 2019 at 6:10 pm

    ErnestPH You need to change “theme_location” to “primary-menu”. That’s Divi specific.

    • Ernesto on May 17, 2019 at 1:27 pm

      Thanks Ivana. Yes it’s working. Perhaps, I didn’t read the tutorial properly. Now, I am changing the Custom WordPress login to this one…

  2. ErnestPH on October 14, 2018 at 2:55 am

    Indeed, this is not working on a DIVI theme and probably other specific themes also. I hope this has a workaround…

    • Neil Gowran on October 14, 2018 at 3:22 am

      It works fine as long as the theme correctly is registering Menus with register_nav_menus, I don’t use Avada but if you find out the Theme location name from support for the menu you want to manipulate and then add it in the code snippet, it will work.

  3. Gibber on January 12, 2018 at 8:52 am

    Hi, can you tell me what exactly should the value on ‘primary’ to it works on my site?

    My ‘Site Menu’ is currently set as the’ Main Navigation’.


  4. Bri on October 20, 2016 at 6:03 pm

    Great snippet thank you.

    Quick question, if I have ‘My Account’ already defined as part of the primary menu then how can I add Login/Logout to that as a sub-menu?

  5. Evan on April 29, 2016 at 12:38 pm

    Any idea why this php snippet is putting the link below the existing secondary menu and not adding it too the three other menu items? Running Divine Theme modified heavily; but core menu structure is default.

Leave all Comment