Add Login Logout link to navigation

This function adds custom links (i.e. loginlogout links) to your specified navigation menu. Change ‘primary_navigation’ to your theme’s registered navbars. (register_nav_menus)

/**
 * Snippet Name: Add Login Logout link to navigation
 * Snippet URL: https://www.wpcustoms.net/snippets/add-loginlogout-link-to-navigation/
 */
  add_filter( 'wp_nav_menu_items', 'add_logout_link', 10, 2);

function add_logout_link( $items, $args )
{
    if($args->theme_location == 'primary_navigation')
    {
        if(is_user_logged_in())
        {
            $items .= '
  • Log Out
  • ‘;
    } else {
    $items .= ‘

  • Log In
  • ‘;
    }
    }

    return $items;
    }

    0 0 vote
    Article Rating
    Subscribe
    Notify of
    guest
    0 Comments
    Inline Feedbacks
    View all comments
    0
    Would love your thoughts, please comment.x
    ()
    x