Skip to content

Instantly share code, notes, and snippets.

@justingreerbbi
Last active August 6, 2025 06:15
Show Gist options
  • Select an option

  • Save justingreerbbi/768f1effcca69b4098c9d0f7731deba0 to your computer and use it in GitHub Desktop.

Select an option

Save justingreerbbi/768f1effcca69b4098c9d0f7731deba0 to your computer and use it in GitHub Desktop.
Logout user using WP REST API WordPress Custom Endpoint
/**
* Head to https://wp-oauth.com for more info on user authentication and custom login and out solutions
* for WordPress
*/
add_action( 'rest_api_init', function () {
register_rest_route( 'wpoauthserver/v1', '/logout/', array(
'methods' => 'GET',
'callback' => 'wp_oauth_server_logout'
) );
} );
function wp_oauth_server_logout() {
wp_logout();
wp_redirect('https://redirect-location.com');
exit;
}
// Call https://site.com/wp-json/wpoauthserver/v1/logout/
@vietkhanh1998
Copy link

it not work ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment