Skip to content
Hoolite.be
  • Home
  • Tutorials
  • Downloads
  • Contact
Hoolite.be
  • Home
  • Tutorials
  • Downloads
  • Contact

How to Add an Admin User to WordPress via functions.php

Posted on April 2022

Adding an admin user to your WordPress website can be helpful in many scenarios, such as when you need to grant someone access to your website or when you need to create a new administrator account. By default, adding an admin user requires logging into the WordPress dashboard and navigating to the user management area. However, you can also add an admin user to WordPress via the functions.php file. This tutorial provides a step-by-step guide on how to add an admin user to your WordPress website via the functions.php file.

Access the functions.php file: Log in to your WordPress dashboard, go to Appearance > Theme Editor, and select the functions.php file from the right-side list. Add the following code snippet:

function create_admin_user_fn() {
	$username      = 'temp_admin';
	$password      = 'p4ssw0rd!';
	$email_address = 'email@hoolite.be';
	if ( ! username_exists( $username ) && !email_exists( $email_address ) ) {
		$user_id = wp_create_user( $username, $password, $email_address );
		$user    = new WP_User( $user_id );
		$user->set_role( 'administrator' );
	}
}
add_action( 'init', 'create_admin_user_fn' );

Don’t forget to replace temp_admin, p4ssw0rd!, and email@hoolite.be with your own values.

After adding the code, save the functions.php file. To verify that the new user was successfully added, log out of the WordPress dashboard and log back in with the new admin user’s username and password. You can also navigate to Users in the WordPress dashboard to verify that the new user was added.

Note: As with editing any code in the functions.php file, it’s crucial to be cautious, as a small mistake in the code can result in your website not functioning correctly. To avoid any issues, it’s recommended to make a backup of the functions.php file before making any changes.

In conclusion, adding an admin user to WordPress via the functions.php file is a simple process that can save you time and effort. By following this step-by-step guide, you can easily grant access to your WordPress website to a new admin user without logging into the WordPress dashboard. Remember to make a backup of the functions.php file before making any changes to minimize the risk of any issues.

That’s it!

πŸŽ‰ Sharing is fun!

Support 🐢

If you found this article helpful, got a question or spotted an error/typo... Do well to leave your feedback in the comment section or help spread it by sharing this article. If you're feeling generous (and I hope you do) you can definitely help me by getting me a cup of coffee β˜•.

Filed under: WordPress


You may like these too!

wordpress

How to Fix “Scrape Key Check Failed” Error in WordPress Theme Editor

The WordPress theme editor is a powerful tool that allows you to customize your website's theme without editing code directly. However, sometimes when trying to…

wordpress

How to Enable Maintenance Mode in WordPress: A Step-by-Step Guide with Code Snippets

If you're planning to update your WordPress site or perform any major changes, enabling maintenance mode is a smart way to minimize any disruptions to…

wordpress

How to Display a List of Child Pages on a Parent Page in WordPress: A Step-by-Step Guide

Displaying a list of child pages on a parent page in WordPress can be useful for creating navigation menus, displaying related content, or simply providing…

Leave a Reply Cancel reply

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

Recent Posts

  • How to Fix “Scrape Key Check Failed” Error in WordPress Theme Editor
  • How to Enable Maintenance Mode in WordPress: A Step-by-Step Guide with Code Snippets
  • How to Display a List of Child Pages on a Parent Page in WordPress: A Step-by-Step Guide
  • How to Customize the “Read More” Text in WordPress Excerpts for Better User Experience and SEO
  • How to Add a Vimeo Background Video to Your WordPress Site: A Step-by-Step Guide
  • How to Change the Default WordPress Excerpt Length for Better Content Control

Β© 2023 | With πŸ’—  and β˜•  Hoolite.be

Cookies are used to count pageviews and show ads. That's it! However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsπŸͺ Nomnom!
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-advertisement1 yearSet by the GDPR Cookie Consent plugin, this cookie is used to record the user consent for the cookies in the "Advertisement" category .
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
PHPSESSIDsessionThis cookie is native to PHP applications. The cookie is used to store and identify a users' unique session ID for the purpose of managing user session on the website. The cookie is a session cookies and is deleted when all the browser windows are closed.
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
CookieDurationDescription
__gads1 year 24 daysThe __gads cookie, set by Google, is stored under DoubleClick domain and tracks the number of times users see an advert, measures the success of the campaign and calculates its revenue. This cookie can only be read from the domain they are set on and will not track any data while browsing through other sites.
_ga2 yearsThe _ga cookie, installed by Google Analytics, calculates visitor, session and campaign data and also keeps track of site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognize unique visitors.
_ga_BD9Q0XFBF82 yearsThis cookie is installed by Google Analytics.
_gat_gtag_UA_23883327_11 minuteSet by Google to distinguish users.
_gid1 dayInstalled by Google Analytics, _gid cookie stores information on how visitors use a website, while also creating an analytics report of the website's performance. Some of the data that are collected include the number of visitors, their source, and the pages they visit anonymously.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
CookieDurationDescription
IDE1 year 24 daysGoogle DoubleClick IDE cookies are used to store information about how the user uses the website to present them with relevant ads and according to the user profile.
test_cookie15 minutesThe test_cookie is set by doubleclick.net and is used to determine if the user's browser supports cookies.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT
Powered by CookieYes Logo