Function Reference of Logout in wordpress

Picture of Woocoders
Woocoders
2nd September 2020

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>

Otherwise you must use:

<a href="<?php echo wp_logout_url( $_SERVER['REQUEST_URI'] ); ?>" 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>

Share this post: