I using this code to logout. It works except on mobile it opens a new window. How can I logout with confirmation and redirect to to the same window?

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://www.example.com';
        $location = str_replace('&', '&', wp_logout_url($redirect_to));
        header("Location: $location");

1 Answer 1


Try using wp_redirect($url). See https://developer.wordpress.org/reference/functions/wp_redirect/ .

So...something like:

// set up the URL to redirect to
$redirect_to = 'https://www.example.com/page';

Note that exit is required to close out the code. See the docs in the above link.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.