Share Article To

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.

4 thoughts on “How to add LogIn and LogOut Link to Custom Menu

  1. How about this ? Small and presize 🙂


    add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);

    function add_login_logout_link($items, $args) {
    $loginoutlink = wp_loginout('index.php', false);
    $items .= ''. $loginoutlink .'';
    return $items;
    }

  2. Great one!! But what we need to do to set the order of the login/logout url in a custom menu. For example how can I place it in the 2nd position(to say) of the custom menu.

  3. if we use it for custom login page then how to use it i mean how to give a spacefic path for login page?anyone help me
    thanks advance 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *