Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp loginout


Displays a login link, or if a user is logged in, displays a logout link. An optional, redirect argument can be used to redirect the user upon login or logout.


 <?php wp_loginout$redirect$echo ); ?> 


(string) (optional) URL to redirect to on login/logout.
Default: None
(boolean) (optional) If true, echos the link, if false, returns the link as a string.
Default: true


Basic Example

<p><?php wp_loginout(); ?></p>

Add Log in/out Link To Nav Menu

Simply add this code to your parent or child themes functions.php file to display a log in/out link in the secondary navigation menu of the Twenty Fourteen default theme for WordPress.

add_filter( 'wp_nav_menu_secondary_items','wpsites_loginout_menu_link' );

function wpsites_loginout_menu_link( $menu ) {
    $loginout = wp_loginout($_SERVER['REQUEST_URI'], false );
    $menu .= $loginout;
    return $menu;

Other themes like Twenty Thirteen may require you to add a class to the code like this example.

$loginout = '<li class="nav-menu" class="menu-item">' . wp_loginout($_SERVER['REQUEST_URI'], false ) . '</li>';


Change Log

Since: 1.5

The $redirect parameter is added in Version 2.8.

Source File

wp_loginout() is located in wp-includes/general-template.php.


Login Tags: is_user_logged_in(), wp_login_form(), wp_loginout(), wp_logout(), wp_register()
Login URLs: wp_login_url(), wp_logout_url(), wp_lostpassword_url(), wp_registration_url()

See also index of Function Reference and index of Template Tags.