Reputation: 427
I have to logout a user from a WordPress site where the top bar is disabled and no logout option is available at any page.
Is there a general link to logout from WordPress?
Upvotes: 18
Views: 60442
Reputation: 1783
You could use the wp_loginout() function that displays the a logout link if user is logged in or login link if it is not.
To add this link to the WordPress menu, check this article. Basically, just add the following code to functions.php:
add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
function add_login_logout_link($items, $args)
{
$loginoutlink = wp_loginout('index.php', false);
$items .= '<li>'. $loginoutlink .'</li>';
return $items;
}
Upvotes: 0
Reputation: 11
You can use the below url:
domian-name.com/wp-login.php?action=logout
Change domain-name.com
with your website's domain name.
After hitting this URL, you will be asked to confirm. That's it.
Upvotes: 1
Reputation: 339
I think the better method is to get the nonce and redirect to the home page:
<a href="<?php echo wp_logout_url( home_url()); ?>" title="Logout">Logout</a>
Upvotes: 20
Reputation: 1001
/wp-login.php?action=logout
Is what was used in the past.
References:
https://codex.wordpress.org/Function_Reference/wp_logout_url https://developer.wordpress.org/reference/functions/wp_logout_url/
Upvotes: 45