wp_logout_url()WP 2.7.0

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

The result is passed through esc_html().

Used By: wp_loginout()
Hooks from the function


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


wp_logout_url( $redirect );
Path to redirect to after the logout.
Default: ''


#1 Get the logout URL in any part of the theme

<a href="<?php echo wp_logout_url(); ?>" title="Logout">Logout</a>

#2 Stay on the current page after the logout

<a href="<?php echo wp_logout_url( get_permalink() ); ?>" title="Logout">Logout</a>

#3 Go to the home page after the logout

<a href="<?php echo wp_logout_url( home_url() ); ?>" title="Logout">Logout</a>

#4 Go to another site after the logout

Suppose you want the user to go to another site after the logout (not necessary the site of the current multisite network). To do that, you need to add the site to the whitelist using allowed_redirect_hosts filter.

function allowed_redirect_site( $allowed ){
	$allowed[] = 'myredirectsite.com';
	return $allowed;

<a href="<?php echo wp_logout_url( 'http://example.com' ); ?>">Logout</a>


Since 2.7.0 Introduced.

Code of wp_logout_url() WP 5.9.3

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 );