Action Hook since 1.5.1

wp_logout

Fires after a user logs out

Description

wp_logout is the mirror of wp_login — use it to clear per-user cookies, caches, or add custom redirect logic.

When it runs

Runs inside wp_logout() after wp_clear_auth_cookie() and wp_destroy_current_session(), just before any redirect on wp-login.php?action=logout.

Signature

do_action( 'wp_logout', int $user_id );

Parameters

  • $user_id int — ID of the user who just logged out.

Examples

Basic

add_action( 'wp_logout', function( $user_id ) {
    delete_transient( 'user_session_' . $user_id );
} );

Clear a custom per-user transient on logout.

Real case

add_action( 'wp_logout', function() {
    wp_safe_redirect( home_url() );
    exit;
} );

Send the user home instead of back to the default wp-login.php screen after logout.

Common Use Cases

  • Clear custom cookies or transients on logout
  • Log a security/audit event
  • Redirect to a custom page after logout
  • Invalidate a cached per-user fragment

Common mistakes

  • Trying to read wp_get_current_user() inside wp_logout — the session is already destroyed by then; use the $user_id argument instead

Related hooks

FAQ

Can I redirect the user somewhere custom after logout?

Yes — hook wp_logout (or the logout_redirect filter for more control over the target URL) and call wp_safe_redirect() followed by exit.

Source: wp-includes/pluggable.php

Group wizard

One session: this hook, then each related_hooks entry. Walk it and tell us what to change.

wp_logout → wp_login

functions.php — wp_logout
functions.php
PHP wp_logout · Hook 1 of 2 · Step 1 of 7

Practice the wp_logout WordPress action hook in our interactive sandbox — a VS Code-style editor with a step-by-step wp_logout tutorial, add_action exercises, and instant feedback. No local WordPress install required.