Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add Login / Logout Links To The Custom Menu Area
add_filter( 'wp_nav_menu_items', 'we_add_loginout_link', 10, 2 );
/**
* Add login/logout and registration links to header menu
*
* @author Bruce Munson, WebEndev
*
*/
function we_add_loginout_link( $items, $args ) {
if (is_user_logged_in() && $args->theme_location == 'header') {
$items .= '<li class="menu-item"><a href="'. wp_logout_url() .'">Log Out</a></li>';
}
elseif (!is_user_logged_in() && $args->theme_location == 'header') {
$items .= '<li class="menu-item"><a href="'. site_url() .'/register/free-lifetime-membership/">Register</a></li>';
$items .= '<li class="menu-item"><a href="'. site_url() .'/login/">Log In</a></li>';
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'we_add_loginout_mobilelink', 10, 2 );
/**
* Add login/logout, My Account, and registration links to mobile menu
*
* @author Bruce Munson, WebEndev
*
*/
function we_add_loginout_mobilelink( $items, $args ) {
if (is_user_logged_in() && $args->theme_location == 'mobile') {
$items .= '<li class="menu-item"><a href="'. site_url() .'/account/">My Account</a></li>';
$items .= '<li class="menu-item"><a href="'. wp_logout_url() .'">Log Out</a></li>';
}
elseif (!is_user_logged_in() && $args->theme_location == 'mobile') {
$items .= '<li class="menu-item"><a href="'. site_url() .'/register/free-lifetime-membership/">Register</a></li>';
$items .= '<li class="menu-item"><a href="'. site_url() .'/login/">Log In</a></li>';
}
return $items;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.