wp_logout Not Logging Me Out

wp_logout() calls clear_auth_cookie(), which expires all authorization cookies set. It doesn’t change the value of the global $current_user variable. So technically you’re still logged in for the duration of the script.

If you’re using wp_logout in your own code, its probably best to exit or wp_redirect immediately afterwards.

You can call wp_set_current_user(0) after wp_logout() to manually log the user out instantly, if you need to continue executing PHP but don’t want the user to be logged in

Leave a Comment