Hi @veshop
You can follow this guide https://pluginsforwp.com/blog/wordpress-logout-link/
It shows you 2 methods, one is to simply add a link like https://yourwebsite.com/wp-login.php?action=logout
which triggers a prompt and requires another click to logout. Simple & effective. But if you want it to work in a single click (As soon as its clicked), there is a piece of code you need to use which is provided later in the article.
Thread Starter
veshop
(@veshop)
Hi @ashfame
no, not working. It crashed my website. When I just use the url for logout, I see a logout in the menu but regarding the page content I still see everything… And when I insert the code snippet my site is crashed. When I try to login, I get immediately a 404. Any other idea?
Thread Starter
veshop
(@veshop)
oK, I found something that does works 🙂
Maybe it helps somebody else too:
1. Create an ‘LogOut’ custom menu item with the link
function redirect_after_logout(){
wp_redirect( home_url() );
exit();
}
add_action('wp_logout', 'redirect_after_logout');
3. To remove the ‘Are you sure you want to logout?’ then also add this to your function.php of your child-theme:
add_action('check_admin_referer', 'logout_without_confirm', 10, 2);
function logout_without_confirm($action, $result)
{
/**
* Allow logout without confirmation
*/
if ($action == "log-out" && !isset($_GET['_wpnonce'])) {
$redirect_to = isset($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : 'url-you-want-to-redirect';
$location = str_replace('&', '&', wp_logout_url($redirect_to));
header("Location: $location");
die;
}
}
1 and 3 were the things mentioned on the link I gave. But glad its working as per your expectation now.