Languages: English • 日本語 (Add your language)
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 ); ?>
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>';
Since: 1.5
The $redirect parameter is added in Version 2.8.
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()