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_idint — 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