How to Let Users Delete Their WordPress Accounts
In this article
Giving users the ability to delete their own WordPress accounts is a key part of data privacy and user autonomy. This guide shows you how to add a self-service account deletion option to your WordPress site, whether you want to remove the user completely or just anonymize their content. You'll need admin access to your WordPress dashboard and, ideally, a staging site to test on first.
What You'll Need
- Administrator access to the WordPress dashboard.
- FTP or file manager access to your server (for manual code edits).
- A child theme if you plan to edit theme files (recommended).
- A staging site or backup to test the changes before going live.
Step-by-Step
- Decide on the deletion behavior. WordPress does not have a native "delete my account" button. You must choose: (a) delete the user and all their content, (b) delete the user but keep their posts (assigning them to another user), or (c) anonymize the user (keep content but remove personal data). This choice determines which method below you use.
- Back up your site. Before making any changes, create a full backup of your database and files. Use a plugin like UpdraftPlus or your host's backup tool. This ensures you can restore if something goes wrong.
- Option A: Use a plugin (easiest). Install and activate a plugin like "Delete Me" or "WP Account Deletion". These plugins add a shortcode or a button to the user's profile page. Configure the plugin settings: choose whether to delete posts or reassign them, whether to require a password confirmation, and where to redirect after deletion. Add the shortcode to a page or the account area.
- Option B: Add a custom function (more control). If you prefer code, add the following to your child theme's
functions.phpfile or a custom plugin. This example adds a "Delete Account" button to the user's profile page that, when clicked, deletes the user and reassigns their posts to a specified user (e.g., admin). - Write the custom function. Use the
delete_user()function in WordPress. Here's a basic example:add_action( 'show_user_profile', 'add_delete_account_button' ); function add_delete_account_button( $user ) { if ( current_user_can( 'delete_user', $user->ID ) ) { echo '<a href="' . wp_nonce_url( admin_url( "admin-post.php?action=delete_my_account" ), 'delete_my_account_' . $user->ID ) . '">Delete My Account</a>'; } } add_action( 'admin_post_delete_my_account', 'handle_delete_my_account' ); function handle_delete_my_account() { $user_id = get_current_user_id(); if ( ! wp_verify_nonce( $_GET['_wpnonce'], 'delete_my_account_' . $user_id ) ) { wp_die( 'Security check failed.' ); } // Reassign posts to admin (ID 1) before deleting wp_delete_user( $user_id, 1 ); wp_logout(); wp_redirect( home_url() ); exit; }This code adds a link on the profile page. When clicked, it verifies the nonce, deletes the user, reassigns their posts to user ID 1 (change this to your admin ID), logs them out, and redirects home. - Test the deletion flow. Log in as a test user (not admin) and try deleting the account. Verify that the user is removed, posts are reassigned or deleted as intended, and the redirect works. Check that the user cannot access the site afterwards.
- Add a confirmation step (recommended). To prevent accidental deletions, add a JavaScript confirmation dialog or a separate confirmation page. For example, use
confirm('Are you sure?')on the button click, or create a page that asks for the user's password before deleting. - Consider GDPR compliance. If you serve EU users, you may need to provide a way for users to request data erasure. The plugin "WP GDPR Compliance" or a custom form can handle this. Ensure you have a privacy policy that explains the deletion process.
- Update your privacy policy. Clearly state that users can delete their accounts and what happens to their data (posts, comments, etc.). This builds trust and is often legally required.
Common Mistakes
- Not testing on a staging site. Editing functions.php directly on a live site can break it. Always test first.
- Forgetting to reassign posts. If you delete a user without reassigning their posts, WordPress will delete all their content. Use the second parameter of
wp_delete_user()to reassign. - Not checking user capabilities. Make sure the delete button only appears for the user themselves, not for admins viewing other profiles. Use
current_user_can()checks. - Ignoring nonce security. Without a nonce, the deletion URL can be forged. Always use
wp_nonce_url()and verify it. - Not logging out after deletion. If you don't log the user out, they may still have an active session and see errors.
Tips
- Use a plugin if you're not comfortable with code. Plugins like "Delete Me" handle the complexity and often include features like email notifications.
- Add a confirmation checkbox or password field. This prevents accidental deletions and ensures the user really wants to leave.
- Redirect to a thank-you page. After deletion, redirect to a friendly page that confirms the account was removed and provides a way to contact support.
- Log the deletion. Add an action hook to log when a user deletes their account for your records.
- Keep the admin account safe. Never allow the admin user to delete their own account via this method. Add a check to exclude user ID 1.
Troubleshooting
- The delete button doesn't appear. Check that you've added the code to the correct file (functions.php of your active theme or a custom plugin). Clear any caching plugins. Ensure the user is logged in and viewing their own profile.
- Getting a "security check failed" error. This means the nonce is invalid. Make sure the link is generated with the correct nonce action and that the user hasn't logged out or switched sessions. Try clearing cookies and re-logging in.
- User is deleted but posts remain. If you didn't pass a second argument to
wp_delete_user(), posts are deleted. If you want to keep them, pass the admin user ID. If posts are still deleted, check that you're using the correct function and that no other plugin is interfering. - White screen after deletion. This often happens if the redirect fails. Check that the redirect URL is valid and that the user is logged out before redirecting. Try using
wp_safe_redirect()instead. - User can still log in after deletion. This may be due to caching or a session that wasn't destroyed. Use
wp_logout()and also callwp_clear_auth_cookie()to ensure the session is cleared. - Deletion works but emails are not sent. Some plugins send notifications. If you're using a custom function, you need to add your own email notification using
wp_mail().
Frequently Asked Questions
Is there a built-in WordPress feature for account deletion?
No, WordPress does not have a native "delete account" button. You must add it via a plugin or custom code.
Will deleting a user delete their posts?
By default, yes, unless you reassign their posts to another user. The wp_delete_user() function accepts a second parameter for the reassignment user ID.
Can I let users delete their accounts without logging in?
No, the user must be logged in to verify their identity. You can also require a password confirmation for extra security.
What happens to comments left by the deleted user?
Comments are also deleted when the user is deleted, unless you reassign them. You may want to keep comments and anonymize them instead.
Is it GDPR compliant to delete accounts?
Deleting accounts is a good step, but you may also need to provide a way for users to request data erasure. Consult a legal expert for full compliance.
Can I undo a user deletion?
Only if you have a backup. That's why it's critical to back up your site before implementing this feature.