No Nonsense WordPress Logout Link Without a Plugin
28
April
Add this WordPress Logout Link snippet and any logged in user can just go to /logout/ and they will be logged out:
// WordPress Logout Link
function sozot_logout_redirect() {
$path = $_SERVER['REQUEST_URI'];
if ( !is_user_logged_in() ) {
return;
}
// Allow Logged in Users to Log out from /logout/
if (preg_match("~/logout~", $path) or is_page('logout')) {
wp_logout();
wp_redirect( wp_login_url().'?loggedout=true' );
exit;
}
}
add_action('template_redirect', 'sozot_logout_redirect');
add_action('login_init', 'sozot_logout_redirect');
No comments yet.