Tagged: woocommerce
Hi there, you said, Enfold ist Woocomerce compatible. How can I integrate a Login / Logout link into the top header?
Insert following code at the bottom of functions.php:
function add_login_logout_link($items, $args)
{
if(is_user_logged_in() && $args->theme_location == 'avia2')
{
$newitems = '<li><a title="'.__('Logout','avia_framework').'" href="'. wp_logout_url(get_permalink()) .'">'.__('Logout','avia_framework').'</a></li>';
$newitems .= $items;
}
else if($args->theme_location == 'avia2')
{
$newitems = '<li><a title="'.__('Login','avia_framework').'" href="'. wp_login_url(get_permalink()) .'">'.__('Login','avia_framework').'</a></li>';
$newitems .= $items;
}else{
$newitems .= $items;
}
return $newitems;
}
add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
You maybe need to replace “avia2” with “avia” or “avia3” (depends on the menu you want to use for the login/logout links).
Great, thx. The Login / Logout is now 1st point in the navigation. Is there a way to put it at the end, just before the search button?
Yes, use following code:
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);
Super, perfekt. Danke!