# Log Out Without the Confirmation Screen

> Logs users out right away from plain logout links (for example in menus) instead of showing "Do you really want to log out?".

- Type: PHP
- Runs: Run everywhere
- Category: [Login](https://wpide.com/library/category/login/)
- Tags: login, logout, ux
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/logout-without-confirmation/

## Code

```php
add_action( 'check_admin_referer', function ( $action, $result ) {
    if ( 'log-out' !== $action || $result || ! is_user_logged_in() ) {
        return;
    }

    wp_logout();

    $target = isset( $_REQUEST['redirect_to'] ) ? wp_validate_redirect( wp_unslash( $_REQUEST['redirect_to'] ), home_url( '/' ) ) : home_url( '/' );

    wp_safe_redirect( $target );
    exit;
}, 10, 2 );
```

## Notes

Without the confirmation step, another site could log your users out with a link; that is an annoyance, not a data risk.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Log Out Without the Confirmation Screen" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
