Your site has been hacked, you're left out, it's frustrating. You've probably tried creating an administrator using an SQL query, but if this method doesn't work, what else can you do? Recently, one of our readers asked if it was possible to add an administrator on WordPress through FTP. The answer will surprise more than one, because it is indeed possible.

In this tutorial, we will show you how to add an administrator on WordPress via FTP.

How to add a user by FTP on WordPress

When will you need to add an administrator via FTP?

Sometimes you can forget your username or email address on your WordPress site, preventing you from signing in to your dashboard.

There are several ways to fix it. One of the methods is using an SQL query, but if you can not connect to phpMyAdmin, you will not be able to execute MySQL queries.

Some users may have a hacked site where their primary account is deleted. In this case, adding an administrator via FTP can quickly restore your access to your dashboard.

That said, we'll see how you add an administrator on WordPress by FTP.

How to add a user by FTP

The first thing you need to have is an FTP client. If you do not control it, you can always make a choice in our list of FTP recommended and then learn how to use it to put WordPress online (FileZilla Cases).

Once connected to your WordPress site, you need to locate the file " functions.php Of your active theme. He is probably in a path similar to this one:

/votresite.com/wp-content/themes/votre-theme-actif/functions.php

By right-clicking on the file functions.php You can download it to your computer.

FTP right-click to download a FileZilla file

Open the file you downloaded to your computer with a notepad (or a text editor of your choice). Now you have to add this code at the end of the file.

function bpc_admin_account () {$ user = 'Username'; $ pass = 'Password'; $ email = '[email protected]'; if (! username_exists ($ user) &&! email_exists ($ email)) {$ user_id = wp_create_user ($ user, $ pass, $ email); $ user = new WP_User ($ user_id); $ user-> set_role ('administrator'); }} add_action ('init', 'bpc_admin_account');

Do not forget to replace " USERNAME  "," mot de passe "And" [email protected] With your own information.

Then save the file and then send it to your website, still via FTP.

You can now login to your site by accessing the login page. This code runs every time WordPress initializes. So you will need to delete it when you get to connect.

I hope that from now on you are able to connect to your website. Remember that the first solution against hacking and everything that prevents you from logging into your dashboard are backups. We have offered you in previous tutorials:

You will also need to know how to protect your blog against attacks. In this case you can use Sucuri or a CDN which also offers an excellent firewall.

If you have any questions, do not hesitate to ask them.