wp_loginout( string $redirect = '', bool $echo = true )

Display the Log In/Out link.


Description Description

Displays a link, which allows users to navigate to the Log In page to log in or log out depending on whether they are currently logged in.


Parameters Parameters

$redirect

(string) (Optional) path to redirect to on login/logout.

Default value: ''

$echo

(bool) (Optional) Default to echo and not return the link.

Default value: true


Top ↑

Return Return

(string|void) String when retrieving.


Top ↑

Source Source

File: wp-includes/general-template.php

function wp_loginout($redirect = '', $echo = true) {
	if ( ! is_user_logged_in() )
		$link = '<a href="' . esc_url( wp_login_url($redirect) ) . '">' . __('Log in') . '</a>';
	else
		$link = '<a href="' . esc_url( wp_logout_url($redirect) ) . '">' . __('Log out') . '</a>';

	if ( $echo ) {
		/**
		 * Filters the HTML output for the Log In/Log Out link.
		 *
		 * @since 1.5.0
		 *
		 * @param string $link The HTML link content.
		 */
		echo apply_filters( 'loginout', $link );
	} else {
		/** This filter is documented in wp-includes/general-template.php */
		return apply_filters( 'loginout', $link );
	}
}

Top ↑

Changelog Changelog

Changelog
Version Description
1.5.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note content
    Contributed by Codex

    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','wpdocs_loginout_menu_link' );
    
    /**
     * Append Login In/Out link to menu with a redirect to this page
     */
    function wpdocs_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>';
    

You must log in before being able to contribute a note or feedback.