Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #325912

    Hi Everyone,

    I added this code in the functions.php to get a login/logout in top menu.

    function add_login_logout_link($items, $args)
    {
    if(is_user_logged_in() && $args->theme_location == 'avia2')
    {
    $newitems = $items;
    $newitems .= '<li><a title="'.__('Logout','avia_framework').'" href="'. wp_logout_url(get_permalink()) .'">'.__('Logout','avia_framework').'</a></li>';
    }
    else if($args->theme_location == 'avia2')
    {
    $newitems = $items;
    $newitems .= '<li><a title="'.__('Login','avia_framework').'" href="'. wp_login_url(get_permalink()) .'">'.__('Login','avia_framework').'</a></li>';
    
    }else{
    $newitems .= $items;
    }
    return $newitems;
    }
    add_filter('wp_nav_menu_items', 'add_login_logout_link', 5, 2);
    

    That workes, but if I click logout, I was forwarded to a 404 page. How can I manage to return to the homepage?

    And second, I have just realised, that this login/logout is for the wp dashboard. How can I get one for the woocommerce shop… sorry.

    Thanks in advance,
    Sophie

    • This topic was modified 10 years, 2 months ago by Sophieja23.
    #325964

    Hey Sophieja23!

    1) Try this code instead

    
    function add_login_logout_link($items, $args)
    {
    if(is_user_logged_in() && $args->theme_location == 'avia2')
    {
    $newitems = $items;
    $newitems .= '<li><a title="'.__('Logout','avia_framework').'" href="'. wp_logout_url(home_url()) .'">'.__('Logout','avia_framework').'</a></li>';
    }
    else if($args->theme_location == 'avia2')
    {
    $newitems = $items;
    $newitems .= '<li><a title="'.__('Login','avia_framework').'" href="'. wp_login_url(home_url()) .'">'.__('Login','avia_framework').'</a></li>';
    
    }else{
    $newitems .= $items;
    }
    return $newitems;
    }
    add_filter('wp_nav_menu_items', 'add_login_logout_link', 5, 2);
    

    2) WooCommerce and wordpress share the same user accounts and logged in/logged out status. There’s no dedicated login/logout link for woocommerce

    Regards,
    Peter

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.