VeeZ Phone
VeeZ Phone

Reputation: 427

How to logout via URL in WordPress?

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

Answers (4)

user8230352
user8230352

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

vs19011988
vs19011988

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

Platoscave
Platoscave

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

Enoch
Enoch

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

Related Questions