- Home
- Knowledge Base
- WordPress
- How to Create a WordPress Admin User by Editing functions.php
How to Create a WordPress Admin User by Editing functions.php
This is an advanced topic. Please contact us if you require assistance or are unsure of the steps
WordPress is a popular content management system used to create websites and blogs. The platform offers a user-friendly interface for managing your website, but sometimes you may need to add an additional user with administrative privileges. In this article, we will show you how to create a WordPress admin user by editing the functions.php file in your theme.
Before You Start
Before you begin, it’s important to make a backup of your website and theme files. This is because making changes to your website’s files can cause errors or break your site if not done properly.
Once you have backed up your website, you will need to access your WordPress file system. You can do this through the file manager in your hosting control panel, or using an FTP client.
Creating a WordPress Admin User
To create a new WordPress admin user, you need to add the following code at the end of your functions.php file:
function add_new_admin_user() {
$username = 'newadmin';
$email = 'newadmin@example.com';
$password = 'NewPassword';
$user_id = wp_create_user( $username, $password, $email );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
}
add_action( 'init', 'add_new_admin_user' );
In this code, replace 'newadmin'
with the desired username for your new user, and replace 'newadmin@example.com'
with the email address for your new user.
Once you have added the code to your functions.php file, save the changes and refresh your website. The new user will now be added to your WordPress installation with administrative privileges.
Important Note: After adding the new user, it is highly recommended that you remove the code from your functions.php file. This is because leaving the code in place could pose a security risk.
Conclusion
Creating a new WordPress admin user can be useful when you need to delegate tasks or give someone else access to your website. By following the steps outlined in this article, you can easily add a new user with administrative privileges by editing the functions.php file in your theme. Just remember to always make a backup of your website and theme files before making any changes, and to remove the code once the new user has been created.
Related Articles
- Understanding and Securing the WordPress REST API
- How to Fix the WordPress White Screen of Death
- 10 Basic Steps for Troubleshooting WordPress Errors
- How to Fix your WordPress Site When It’s Experiencing a Critical Error
- What is WP-CLI? A Comprehensive Guide by SmartHost
- How to Change Sender Name in Outgoing WordPress Emails
Leave A Comment