How to create new wordpress admin user programmatically

In this article we will show you How to create new wordpress admin user programmatically.Losing your access to your WordPress website is frustrating, but fortunately, there are some ways to recover your account.

You may also like,

How to Create a Custom WordPress Theme
WordPress Files and Directory Structure

Why we might need to create new WordPress admin user programmatically via FTP?

Sometimes, you lose your credentials and you can’t log in to your WordPress admin dashboard, or you might get your Website hacked and you lose your own website account.
In any of these cases, restoring your account via FTP is easy and fast.

Login to your website using FTP

To do this, you will need to have an FTP client to login to your website.
After connecting to your website, you need to find a file called function.php in your theme’s root folder, this folder path could be something like this:


Now after locating your function.php file, you need to download the file to your local computer or directly Edit your file using any editor.

Create an Admin account

To create an admin account, you will need to add the code below to the end of your function.php file:

Don’t forget to replace Username and Password and with your own info. Now you will need to save the file, and upload it to your theme folder and login to your admin panel.

After doing this, you will need to delete the code that we already added since this won’t delete the user you created, and this will make your info safe in case anyone else have access to your FTP.

I hope I helped you, and in any case, don’t hesitate to contact me.

Share this: