WordPress

How to remove a user from WordPress using functions.php

  1. 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>');
  }
}
  1. Visit your website.
  2. Remove the code from functions.php

See Function Reference wp delete user – WordPress Codex

Was this guide helpful?

Need help with this?

Open a ticket and link to this guide so our team can see what you have tried.

View support tickets

Power your business with Ecenica Hosting

Built for WordPress and serious websites. Fast, secure and supported by real people in the UK.

Ecenica hosting services represented by a connected red route across London