Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hazratbilal0079/045422eadf4604df6e1c93509a38343c to your computer and use it in GitHub Desktop.
Save hazratbilal0079/045422eadf4604df6e1c93509a38343c to your computer and use it in GitHub Desktop.
Logout and Redirect to Specified Page Functionality for WordPress Logout Button without alert messages
-- Link on Button or Icon
https://yourwebsite.com/wp-login.php?action=logout
--Php Function or Code Snippet
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'] : 'https://yourwebsite.com/login';
$location = str_replace('&', '&', wp_logout_url($redirect_to));
header("Location: $location");
die;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment