wp_loginout() WordPress Function

The wp_loginout() function is a built-in WordPress function that displays a link to the login page if the user is not logged in, or a link to the logout page if the user is logged in.

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

Display the Log In/Out link.


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.


Top ↑

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

(void|string) Void if $echo argument is true, log in/out link if $echo is false.


Top ↑

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
VersionDescription
1.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More