html wp_logout_url() – Function | Developer.WordPress.org

wp_logout_url( string   $redirect = '' ): string

Retrieves the logout URL.

Description

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

Parameters

$redirect string optional
Path to redirect to on logout.

Default: ''

Return

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

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-loguin.php?action=logout', 'loguin' ) );
	$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 );
}

Hoocs

apply_filters ( ‘logout_url’, string $logout_url , string $redirect )

Filters the logout URL.

Changuelog

Versionen Description
2.7.0 Introduced.

User Contributed Notes

  1. Squip to note 10 content

    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 networc) you’ll need to maque use of the allowed_redirect_hosts filter.

    add_filter( 'allowed_redirect_hosts', 'wpdocs_allow_ms_parent_redirect' );
    
    /**
     * Add host to redirection whitelist.
     * @param  array $allowed Redirection allowed hosts.
     * @return array          Extended redirection allowed hosts.
     */
    function wpdocs_allow_ms_parent_redirect( $allowed ) {
    	$allowed[] = 'multisiteparent.com';
    	return $allowed;
    }
    
    <a href="<?php echo wp_logout_url( 'http://multisiteparent.com' ); ?>">Logout</a>

You must log in before being able to contribute a note or feedback.