Retrieves the logout URL.
Description
Returns the URL that allows the user to log out of the site.
Parameters
$redirect
stringoptional- Path to redirect to on logout.
Default:
''
Source
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 );
}
Hooks
- apply_filters( ‘logout_url’,
string $logout_url ,string $redirect ) Filters the logout URL.
Changelog
Version | Description |
---|---|
2.7.0 | Introduced. |
This example shows how to logout and redirect to current page inside the loop.
This example shows how to logout and redirect to homepage.
This example shows how to logout and redirect to another site. If you are using wp_logout_url to redirect to another site on logout (e.g. another subsite in a MultiSite network) you’ll need to make use of the allowed_redirect_hosts filter.
Default Usage.
Logout redirect to home page
Default Safe Usage.
I had to use a PHP function
to replace
& amp;
with&
or the warning won’t disappear.