Skip to main content
Corrected a typo and removed an extra semicolon and added a clarification for the redirect URL.
Source Link

If you can't use wp_logout_url() funcitionfunction, You can turn off this validation using this code:

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;
    }
}

Replace 'url-you-want-to-redirect' with the URL you want to redirect after logout.

Add it in your functions.phpfunctions.php

If you can't use wp_logout_url() funcition, You can turn off this validation using this code:

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'] : '';
        $location = str_replace('&', '&', wp_logout_url($redirect_to));;
        header("Location: $location");
        die;
    }
}

Add it in your functions.php

If you can't use wp_logout_url() function, You can turn off this validation using this code:

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;
    }
}

Replace 'url-you-want-to-redirect' with the URL you want to redirect after logout.

Add it in your functions.php

Source Link

If you can't use wp_logout_url() funcition, You can turn off this validation using this code:

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'] : '';
        $location = str_replace('&', '&', wp_logout_url($redirect_to));;
        header("Location: $location");
        die;
    }
}

Add it in your functions.php