wp_logout_url() WordPress Function

This function allows you to create a URL for logging out of WordPress. It takes one parameter, which is the URL to redirect to after logging out.

wp_logout_url( string $redirect = '' ) #

Retrieves the logout URL.


Description

Returns the URL that allows the user to log out of the site.


Top ↑

Parameters

$redirect

(string)(Optional)Path to redirect to on logout.

Default value: ''


Top ↑

Return

(string) The logout URL. Note: HTML-encoded via esc_html() in wp_nonce_url().


Top ↑

Source

File: wp-includes/general-template.php

function wp_logout_url( $redirect = '' ) {
	$args = array();
	if ( ! empty( $redirect ) ) {
		$args['redirect_to'] = urlencode( $redirect );
	}

	$logout_url = add_query_arg( $args, site_url( 'wp-login.php?action=logout', 'login' ) );
	$logout_url = wp_nonce_url( $logout_url, 'log-out' );

	/**
	 * Filters the logout URL.
	 *
	 * @since 2.8.0
	 *
	 * @param string $logout_url The HTML-encoded logout URL.
	 * @param string $redirect   Path to redirect to on logout.
	 */
	return apply_filters( 'logout_url', $logout_url, $redirect );
}


Top ↑

Changelog

Changelog
VersionDescription
2.7.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