- Add the following code to your themes functions.php file to remove a user from your WordPress site.
//remove a user from WordPress by WP username
add_action( 'init', 'ec_delete_user');
function ec_delete_user() {
require_once( ABSPATH . 'wp-admin/includes/user.php' );
$username = 'ecenica';
if ( username_exists( $username ) ) {
$user = get_user_by( 'login', $username );
$success = wp_delete_user( $user->ID );
wp_die('wp delete gave: <pre>"'.print_r($success).'"</pre>');
}
}
- Visit your website.
- Remove the code from functions.php
See Function Reference wp delete user – WordPress Codex
Was this guide helpful?
Thanks for your feedback — it helps us improve our guides.
Need help with this?
Open a ticket and link to this guide so our team can see what you have tried.
View support tickets