How to lock down WordPress admin access
WordPress already blocks logged-out visitors from wp-admin, but you should still limit admin capabilities, enable two-factor authentication, disable dashboard file editing and add server-level protection where appropriate. For role-based redirects, use a small custom plugin or a security plugin.
- 01Decide who needs admin access
- 02Strengthen administrator sign-in
- 03Disable dashboard file editing
- 04Restrict wp-admin manually
- 05Add server-level protection carefully
- 06Test the lockout before leaving
- 07Use a management plugin for complex rules
What you need
- Administrator or hosting access
- A recent backup of the site
- A way to edit wp-config.php or install a small custom plugin
- Two-factor authentication available for administrator accounts
Decide who needs admin access
Start by listing the people who genuinely need the WordPress dashboard and what each person must do. WordPress roles control capabilities such as publishing, moderating comments, managing plugins and changing settings, so do not give every account the Administrator role. Grant only the capabilities required for the job.
Check Users and remove old accounts, shared logins and unused administrator accounts. Use separate named accounts so you can revoke one person’s access without changing everyone else’s password. WordPress recommends using roles and capabilities rather than treating every user as an administrator.
Strengthen administrator sign-in
Use long, unique passwords for administrator accounts and enable two-factor authentication through a reputable security or identity plugin. Keep WordPress, themes and plugins updated, because outdated software is a common route into a site. WordPress’s hardening guidance specifically recommends two-step authentication and regular updates.
Do not treat a changed login URL as your main protection. It may reduce casual scanning, but it does not replace strong authentication, limited privileges, updates and monitoring.
Disable dashboard file editing
Add define( 'DISALLOW_FILE_EDIT', true ); to wp-config.php, above the line that says WordPress should stop editing. This removes the built-in theme and plugin editor from the dashboard, reducing the damage an attacker could do after gaining an administrator session.
This does not prevent malicious uploads or replace a firewall. It also means you must update files through your normal deployment, hosting or file-management process. WordPress documents this constant as a hardening measure.
Restrict wp-admin manually
For a simple site, a small site-specific plugin can redirect logged-in users who lack a chosen capability. The usual place to run this check is admin_init, and the check should use current_user_can() rather than comparing a role name. Exclude AJAX requests with wp_doing_ajax(), because admin-ajax.php can support front-end features for non-administrator users.
The logic is: if the current user lacks the required capability and the request is not AJAX, send them to a permitted front-end page or show an access-denied response, then stop execution. Keep the code in a custom plugin rather than a theme, so changing themes does not remove the restriction. The admin_init hook runs for admin screens as well as admin-ajax.php and admin-post.php, which is why the exclusions matter.
This manual route is fine when you have one clear rule, such as allowing only users with manage_options into the dashboard. It becomes awkward when different roles need different screens, redirects, exceptions or a settings interface.
Add server-level protection carefully
If the site needs a second barrier, ask your host about password-protecting wp-admin/ or limiting it by VPN or IP address. Server-level protection sits before WordPress and can stop many automated requests before WordPress loads.
Test every front-end form, editor, checkout and logged-in feature afterwards. A blanket password rule on wp-admin/ can break admin-ajax.php, and some maintenance endpoints do not load plugins or themes, so a WordPress redirect cannot cover every URL. WordPress documents this trade-off in its hardening guidance.
Test the lockout before leaving
Use a separate test account for each role. Confirm that administrators can sign in, editors can perform their assigned work, restricted users reach the intended page and logged-out visitors cannot access the dashboard. Also test media uploads, front-end forms, REST-powered blocks and any membership or ecommerce workflows.
Keep an administrator session open while testing. The common Friday failure is redirecting every admin request, including AJAX or a plugin’s required background request, then locking yourself out of the tools needed to fix it. If a redirect loop appears, disable the custom plugin through hosting file access or your host’s recovery tools, then inspect caching, security plugins and server rules.
Use a management plugin for complex rules
If you need to hide dashboard sections, restrict wp-admin access for several user groups and redirect public pages while a site is being used mainly for management, MainWP Clean and Lock is a more convenient route than maintaining custom code. It is aimed at making a management site less visible and centralising these controls.
The manual approach is still a good choice for one straightforward capability check. Choose the plugin route when you need configurable restrictions, multiple sites or an interface that other administrators can maintain without editing PHP.
Let MainWP Clean and Lock do it
Hides dashboard sections, restricts wp-admin access, and redirects public pages when you need to make a management site less visible.
Sources
- wordpress.org /documentation/article/roles-and-capabilities/?utm_source=op…
- developer.wordpress.org /advanced-administration/security/hardening/?utm_source=open…
- developer.wordpress.org /reference/hooks/admin_init/?utm_source=openai
Questions
- Does WordPress already block visitors from wp-admin?
- Yes. Unauthenticated visitors are normally sent to the login screen or denied access when they request wp-admin, so you do not need to hide the dashboard just to stop anonymous visitors. The useful hardening work is limiting logged-in users, protecting administrator accounts, disabling file editing and keeping software updated. Server rules may still be useful as an additional barrier.
- Can I stop Editors or Authors from opening wp-admin?
- Yes. Use a capability-based check in a small custom plugin, commonly on the admin_init hook, and redirect users who lack the capability you choose. Do not simply compare the displayed role name, because capabilities are more flexible and custom roles may not match the standard WordPress roles. Exclude AJAX and test front-end features before applying the rule to a live site.
- Should I block the whole wp-admin folder with.htaccess?
- Usually not without checking what the site uses. A server-level password or IP restriction adds protection before WordPress loads, but a blanket rule can interfere with admin-ajax.php, front-end forms, ecommerce features and other logged-in requests. If you use it, follow your host’s method, allow required endpoints and test the site from both public and administrator sessions.
- Is hiding the WordPress login URL enough?
- No. Changing or hiding the login URL is only an obscurity measure and should not be your main defence. Use unique passwords, two-factor authentication, limited user capabilities, current software, backups and disabled dashboard file editing. A hidden URL can also make recovery harder if administrators do not document where the real login page is.
- What is the fastest way to lock down WordPress admin access?
- The fast route is to remove unused administrator accounts, assign the smallest suitable roles, enable two-factor authentication, add DISALLOW_FILE_EDIT to wp-config.php and use a security or management plugin for role-based redirects. MainWP Clean and Lock is suitable when you also want to hide dashboard sections and make a management site less visible without maintaining custom PHP.