WordPress Snippets at WPcustoms

Add Login Logout link to navigation

This function adds custom links (i.e. login\logout 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: http://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; }