WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp logout url

Description

This Template Tag returns the URL that allows the user to log out of the site.

Usage

 <?php echo wp_logout_url$redirect ); ?> 

Parameters

$redirect
(string) (optional) URL to redirect to on logout.
Default: None

Examples

Default Usage

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

Logout and Redirect to Current Page

If inside the loop you can use:

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

Logout and Redirect to Homepage

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

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

add_filter('allowed_redirect_hosts','allow_ms_parent_redirect');
function allow_ms_parent_redirect($allowed)
{
    $allowed[] = 'multisiteparent.com';
    return $allowed;
}

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

Notes

Change Log

Since: 2.7.0

Source File

wp_logout_url() is located in wp-includes/general-template.php.

Related

Login Tags: is_user_logged_in(), wp_login_form(), wp_loginout(), wp_logout(), wp_register()
Login URLs: wp_login_url(), wp_logout_url(), wp_lostpassword_url(), wp_registration_url()

See also index of Function Reference and index of Template Tags.