Created
November 5, 2012 06:24
-
-
Save kloon/4015657 to your computer and use it in GitHub Desktop.
WooCommerce add login/logout buttons to wordpress menu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( woocommerce_get_page_id( 'myaccount' ) ) ) .'">Log Out</a></li>'; | |
} | |
elseif (!is_user_logged_in() && $args->theme_location == 'primary') { | |
$items .= '<li><a href="' . get_permalink( woocommerce_get_page_id( 'myaccount' ) ) . '">Log In</a></li>'; | |
} | |
return $items; | |
} |
Hi ait1,
Can you help me?
In my theme (replay theme (themeforest)) my login logout menu for woocomerce dont work... :(::(
I'd like the Login and logout to go in a dropdown menu. Not to be added on to the menu as the last list item. How can I control where it goes? My last list item is 'My Account' and I want it under there as a dropdown.
Nice tip, Is it possible to create a shortcode as well?
I just use:
Logout Link: /?customer-logout=true
Login: /my-account/
But then it redirects to the dashboard and asks for confirmation if you really want to log out
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, more filtered
Add to functions.php
add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );
function add_loginout_link( $items, $args ) {
if (is_user_logged_in()) {
$items .= '
}
elseif (!is_user_logged_in()) {
$items .= '
}
return $items;
}