wp_logout_url
Retrieves the logout URL.
Description
(string) wp_logout_url( (string) $redirect = '' );
Returns the URL that allows the user to log out of the site.
Returns (string)
The logout URL. Note: HTML-encoded via esc_html() in wp_nonce_url().
Parameters (1)
- 0. $redirect — Optional. (string) =>
''
- Path to redirect to on logout.
Usage
if ( !function_exists( 'wp_logout_url' ) ) { require_once ABSPATH . WPINC . '/general-template.php'; } // Path to redirect to on logout. $redirect = ''; // NOTICE! Understand what this does before running. $result = wp_logout_url($redirect);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/general-template.php
- function wp_logout_url($redirect = '') {
- $args = array( 'action' => 'logout' );
- if ( !empty($redirect) ) {
- $args['redirect_to'] = urlencode( $redirect );
- }
- $logout_url = add_query_arg($args, site_url('wp-login.php', '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 );
- }