"Login / Register" change to "Logout"

Hello guys,

could You advice, how can I change “Login / Register” link to “Logout” when user is logged in?

Hello there,

To achieve that goal, add this function to your child theme’s functions.php file. Or you can use a plugin that allows PHP function addition like Code Snippets.

/**
 * Enable Log Out link
 */

 add_action( 'wp_enqueue_scripts', 'leto_child_logout_link', 9999 );
 function leto_child_logout_link() {

   $wc_pages = array(
     'logout' => wp_logout_url(),
   );

   wp_localize_script( 'leto-main', 'wc_pages', $wc_pages );

 }

Then do the below steps:

  1. Install and activate the TC Custom JavaScript plugin
  2. Go To Appearance > Custom JavaScript
  3. Paste the following code into the provided box
(function($){

  if( $('body').hasClass('logged-in') && $('.nav-link-account').length ) {
    var logoutLink = wc_pages.logout;
    $('.nav-link-account > a').attr('href', logoutLink).text('Log Out');
  }

})(jQuery);
  1. Update

Regards,
Kharis

Thank you very much for quick response, Your theme is awesome :slight_smile:

You’re welcome! Thank you for choosing Leto.

Regards,
Kharis