# Skip "Are You Sure You Want to Log Out?" for Menu Links

> Adds the security token to My Account log out links placed in your navigation menus, so customers log out in one click instead of seeing a confirmation page.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, my-account, logout, menus
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-menu-logout-nonce/

## Code

```php
add_filter( 'wp_nav_menu_objects', function ( $items ) {
    if ( ! function_exists( 'wc_get_account_endpoint_url' ) || ! is_user_logged_in() ) {
        return $items;
    }

    $logout = untrailingslashit( wc_get_account_endpoint_url( 'customer-logout' ) );

    foreach ( $items as $item ) {
        if ( untrailingslashit( strtok( (string) $item->url, '?' ) ) === $logout ) {
            $item->url = wc_logout_url();
        }
    }

    return $items;
} );
```

## Notes

Point a custom menu link at /my-account/customer-logout/ and this snippet turns it into a direct, secure log out link.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Skip "Are You Sure You Want to Log Out?" for Menu Links" 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/
