skip to Main Content

Create A Logout Link in WordPress that Does not Require Confirmation

It seems to be crazy but it is ot standard to simply have a logout linkin wirdPress that you can click on and that just logs you out without any further prompt. BUt there is help. rop this little snippet in your functions.php and you are good to go. Afterwards you can have a logout linkin the frontend and you will no more be bugged by the “Are you sure to do this” annoying confirmation dialog.


add_action('check_admin_referer', 'logout_without_confirm', 10, 2);function logout_without_confirm($action, $result) {// Allow logout without confirmationif ($action == "log-out" && !isset($_GET['_wpnonce'])) {$redirect_to = isset($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : '';$location = str_replace('&', '&', wp_logout_url($redirect_to));;header("Location: $location");die;}}

Back To Top