Tag Archives: log out link in menu

How to add LogIn and LogOut Link to Custom Menu

Today I am going to add one interesting post which will teach you How to add LogIn and LogOut Link to Custom Menu

Yesterday I am trying to do so but did understand how to, and after searching google a lot got few nice links and here I am going to summarize the solution.

add_filter('wp_nav_menu_items', 'wp_custom_login_logout_link', 10, 2);
function wp_custom_login_logout_link($items, $args) {
$login = __('Login Text');
$logout = __('Logout Text');

$menu_name = ”; //provide name you gave to the menu
$redirect = ”; //provide redirection path url

if ( ! is_user_logged_in() )
$link = ‘<a href=”‘ . esc_url( wp_login_url($redirect) ) . ‘”>’ . $login . ‘</a>';
else
$link = ‘<a href=”‘ . esc_url( wp_logout_url($redirect) ) . ‘”>’ . $logout . ‘</a>';

if ( ($menu_name) && ($args->menu == $menu_name) )
$items .= ‘<li>’. $link .'</li>';

return $items;
}

In the above code provide the data `$menu_name` and `$redirect` variables.

If you have any problem regarding this post feel free to write a comment.