Return to Snippet

Revision: 69042
at April 9, 2015 12:35 by entreprenerds


Initial Code
add_filter( 'wp_nav_menu_items', 'add_login_logout_to_primary_menu', 10, 2 );
function add_login_logout_to_primary_menu( $items, $args ) {
    if( 'primary' === $args->theme_location ) :
        
        if (is_user_logged_in()) {
            $items .= '<li><a href="'.wp_logout_url(home_url()).'">Logout</a></li>';
        } else {
            $items .= '<li><a href="'.wp_login_url().'">Login</a></li>';
        }

    endif;
    return $items;
}

Initial URL

                                

Initial Description
Adds a Logout link to the end of your Primary Navigation is the user is logged in; else adds a Login link to the end of your Primary Navigation.

Initial Title
Add Login / Logout to Primary Menu

Initial Tags
php, wordpress

Initial Language
PHP