0% found this document useful (0 votes)
42 views

How To Add An Admin User in Wordpress Using Functions PHP File

If you forget your admin password and not able to log in as an admin then you need to create a new admin user through the functions.php file

Uploaded by

Aman Mehra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

How To Add An Admin User in Wordpress Using Functions PHP File

If you forget your admin password and not able to log in as an admin then you need to create a new admin user through the functions.php file

Uploaded by

Aman Mehra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Blog Categories  Tips & Tricks Contact

HOME
WORDPRESS HOW TO ADD AN ADMIN USER IN WORDPRESS USING FUNCTIONS PHP FILE?
FOLLOW US
Stay updated via social channels

How to Add an Admin User in WordPress


Using Functions PHP File?
HOW TO
WORDPRESS
RECENT POSTS
AMAN MEHRA
JUNE 16, 2021
LEAVE A COMMENT
How to Re-Order WordPress Posts
Tweet on Twitter
Share on Facebook
By Custom Field?

How to Add Title Attribute in


WordPress Menu?

How to Add an Admin User in


WordPress Using Functions PHP
File?

How to Make a Custom Login


Page in WordPress?

How to Create a Custom Widget in


WordPress?

CATEGORIES

How To
Admin users of WordPress have full control of the website and all the
capabilities and can access everything in the admin area. So in case, you want Laravel

to add an admin user in WordPress with a code, then you have to write the code PHP
in the functions.php file.
ReactJS

So, in this article, we will learn how to add an admin user in WordPress using WooCommerce

the functions.php file. WordPress

You can do this with FTP (FileZilla) OR through cPanel directly.

MOST VIEWED POSTS


Let’s start with it.
WooCommerce Remove
Update Cart Button and
Make it Automatically
Table of Contents Update.
1
Why You Want to Add an Admin User in WordPress Using Code October 5, 2020

(Functions.php file)
How to Redirect to
2
Add an Admin User in WordPress Using functions.php file (With FTP) Checkout After Add to
Cart?
3
Add an Admin User in WordPress (With cPanel) October 16, 2020

How to Change Price of


Specific Product and
Why You Want to Add an Admin User in Quantity in Cart?

WordPress Using Code (Functions.php file) October 14, 2020

How can I Prevent SQL


There can be many cases like: Injection in PHP?
October 7, 2020

Forget username and password


Upload Multiple Featured
Your site is hacked
Images in a Post OR Page
Blocked login attempt January 4, 2021

When you forget the username/email address and password, and if your site
hacked and you are not able to login to the admin dashboard, then you may
need to add a new admin user using code in the functions.php file. TIPS & TRICKS

WooCommerce Redirect to
You can also use phpMyAdmin to add an admin user to WordPress using SQL Checkout
query with have database access. But if you may not familiar with the database
How to Remove the WordPress
and afraid to run SQL queries directly in the database. Login Error Shake Effect

Get Unique Values From a


Then it’s better to use the functions.php file to add an admin user in WordPress.
JavaScript Array
You have to add a simple function that is super easy and once it is done then
Create Laravel Model, Migration,
you have to remove that function from the file.
Controller, and Resource in One
Command
Let’s jump on the main point of this article.
Copy to Clipboard with JavaScript
– (also for hidden element)
Add an Admin User in WordPress Using
functions.php file (With FTP)

To add an admin user in WordPress, you need an FTP (File Transfer Protocol)
client-server on your computer. You can use FileZilla OR Cyberduck.

OK. Let’s connect to the website through FTP credentials. When you are
connected and able to see your website files. You will see the screen below.

FTP – Connected to the Website

Then move on to your active theme’s functions.php file by visit the following
path.

/root/wp-content/themes/your-active-theme/functions.php

I’ll suggest you use a child theme to add the custom code. Here are step by
step guide on how to create a WordPress child theme

And here you will see the functions.php file. To edit this functions.php file with
right-click on it and then click the View/Edit option. It will open the file in the
editor and you can edit it now.

FTP – Edit the functions.php file

When the file opened in the editor, you have to add a custom function code at
bottom of the file. So add the below code in your theme’s functions.php file and
save it and upload it through FTP.

1 //add a new admin user to WordPress


2 add_action( 'init', 'add_new_admin_user');
3 function add_new_admin_user() {
4
5 $username = 'wsername';
6 $password = 'password';
7 $email_address = 'your@email.com';
8
9 if ( ! username_exists( $username ) && !email_exists(
10 $user_id = wp_create_user( $username, $password, $e
11 $user = new WP_User( $user_id );
12 $user->set_role( 'administrator' );
13 }
14 }

NOTE: Remember to replcae $username, $password, and $email_address


variable’s values with your own values.

The above code will execute when finished the loading of your website from the
frontend.

We used the init action hook for this. You can read more about init
here.

Now visit the WordPress admin login page and sign with the username and
password that you have just created. You will see, you can log in to the admin
dashboard area now.

OK. Now open your functions.php file again and remove that function from the
file.

NOTE: Don’t worry. It will not remove the user from the WordPress that you have
just added.

Add an Admin User in WordPress (With cPanel)

For this method, you must have cPanel access to edit the file of your website.

To add an admin user in WordPress using cPanel, follow the below steps:

Login to your cPanel account

Open the active theme folder

You will see the functions.php here

Right click on the functions.php file and click on the Edit option

It will open the file in edit mode and you can add the above function in this
file at bottom

Save it and test with your username and password

Once it done, remove that function from file and save it

That’s it

Hope you understand this article about how to add an admin user in WordPress
using functions php file. If you still have any questions, you can ask me in the
comment section, I’ll help you with that.

ADD USER WITH FTP ADD WORDPRESS ADMIN USER ADMIN FTP FUNCTIONS FILE
FUNCTIONS.PHP PHP FUNCTION WORDPRESS WORDPRESS ADMIN
WORDPRESS ADMIN USER WORDPRESS USER

Tweet on Twitter
Share on Facebook

YOU MAY ALSO LIKE

How to Re-Order WordPress Posts By How to Add Title Attribute in


Custom Field? WordPress Menu?

How to Make a Custom Login Page in How to Create a Custom Widget in


WordPress? WordPress?

How to Hide Specific Products from How to Use Where Condition in


Shop Page and Search Page in Laravel Eloquent?
WooCommerce?

ABOUT THE AUTHOR: AMAN MEHRA


Hey! I'm Aman Mehra and I'm a full-stack developer and have 5+
years of experience. I love coding and help to people with this blog.

LEAVE A REPLY

Your email address will not be published. Required fields are marked *

Comment

Name * Email * Website

Save my name, email, and website in this browser for the next time I comment.

POST COMMENT

ABOUT QUICK LINKS RECENT POSTS GET IN TOUCH

Your Blog Coach is the best site Blog How to Re-Order WordPress
Name
for finding the solution to any Posts By Custom Field?
WordPress
issue related to coding and learn
How to Add Title Attribute in Your email address
more cool stuff and tricks. WooCommerce
WordPress Menu?
Contact
How to Add an Admin User in SIGN UP
WordPress Using Functions PHP
File?

© 2020 Your Blog Coach Privacy Policy


Terms and Conditions
Sitemap

You might also like