In part 1 we locked down wp-config.php, and in part 2 we added headers that protect visitors’ browsers. This part is about the front door: the login. Every WordPress site has one at the same address, so bots try passwords on yours whether your site is big or small. The aim is simple: make guessing slow and pointless, and make sure you’d notice if someone did get in.
Before you start
- An administrator accountAnd a second way in, such as FTP or your host’s file manager, in case you lock yourself out
- A way to add PHP snippetsChild theme, must-use plugin or a snippets plugin
- A private browser windowTo test each change as a logged-out visitor
How bots attack a WordPress login
Three things make the login an easy target:
- Usernames are easy to find. WordPress lists authors at
/wp-json/wp/v2/users, and/?author=1redirects to your first user’s archive with the username in the address. Its login errors also say whether a username exists. - Guessing is unlimited. WordPress lets anyone try passwords as fast as they like, on
wp-login.phpand through XML-RPC. - Passwords get reused. If one of your users’ passwords leaked from another site, bots will try it on yours.
Each section below closes one of these gaps.
Stop giving away usernames
A bot that knows your username only has to guess the password. This snippet removes the public users endpoint for logged-out visitors and stops /?author=1 revealing a username. Logged-in requests, including the block editor, keep working.
Then make the login form give one message for every failed attempt, so it no longer confirms which usernames are real:
WordPress shows a user’s display name in bylines and comments, and by default it’s the login username. Under Users → Profile, set Display name publicly as to something other than the username for every author.
In a private window, yoursite.com/wp-json/wp/v2/users returns a 404, yoursite.com/?author=1 goes to the homepage, and a wrong username and a wrong password show the same login error.
Slow down password guessing
This snippet counts failed logins for each IP address and locks that address out for 15 minutes after five failures. It works on wp-login.php, WooCommerce’s My Account login and anything else that signs in through wp_signon(). During a lockout even the right password is refused, so a bot can’t keep guessing in the background.
The snippet reads the visitor’s IP address from REMOTE_ADDR. Behind a proxy that is the proxy’s address, so every visitor would share one counter and five bad logins would lock out everyone. Ask your host to restore real visitor IPs before you add it.
I locked myself out3 common fixes
- Wait 15 minutes. The lockout clears itself.
- In a hurry? Delete the rows starting with
_transient_nahnu_ll_from thewp_optionstable in phpMyAdmin. - Locked out repeatedly? Check that a password manager or an old app isn’t retrying an old password in the background.
Close the side doors
The login page isn’t the only way to try a password.
XML-RPC is an old remote-publishing interface that’s still switched on by default. Its system.multicall method lets a bot test hundreds of passwords in a single request, which also slips past per-request limits. Unless you use Jetpack or the WordPress mobile app, turn it off:
Application passwords let apps and services sign in to the REST API for a user. They’re useful for integrations, but if nothing on your site uses them, they’re one more way in for someone who gets into an account:
Jetpack and the official WordPress mobile apps connect over XML-RPC. Some backup, deployment and Zapier-style services use application passwords. If you’re not sure, look at the Application Passwords section on each administrator’s profile: anything listed there is in use.
Make stolen passwords useless
Everything above slows attackers down. This section is what actually stops them.
Require long passwords. WordPress warns about weak passwords but lets users tick “Confirm use of weak password” and carry on. This snippet sets a real minimum of 12 characters, and refuses passwords that contain the username:
Turn on two-factor login for everyone who can edit the site. With a second factor, such as a code from an authenticator app or a security key, a leaked or guessed password is not enough to sign in. WordPress doesn’t include two-factor login, so use a plugin. The free Two Factor plugin is maintained by WordPress contributors and supports authenticator apps, email codes and backup codes. For passkeys or hardware security keys, add its companion plugin, Two-Factor Provider: WebAuthn. Start with administrators, then editors and shop managers.
When you turn on two-factor login, save the backup codes in your password manager. They are how you get back in if you lose your phone.
Know when someone gets in
If someone does log in with an administrator’s password, the owner of that account should find out straight away. This snippet emails administrators when their account signs in from an IP address it hasn’t used recently:
Expect a few extra emails if you log in from a phone or a connection that changes IP address often. That’s the trade-off for knowing.
What about hiding the login page?
Moving or hiding wp-login.php stops most bots from finding it, which means quieter logs and less load on your server. It’s a reasonable extra, as long as you treat it as one: it hides the door but doesn’t lock it. Anyone who finds the address faces the same login as before. If you want it, our snippet keeps logouts, password resets and saved logins working:
Add it last, after everything above, and bookmark your secret link before you log out.
Login hardening checklist
0 / 9Summary
Start by giving away less: block username lookups and use one generic login error. Then limit failed logins and switch off XML-RPC if you don’t need it. The two changes that matter most are long passwords and two-factor login, because they make a guessed or stolen password useless. Add login alerts so you’d know if something slipped through. Hiding the login page is optional, and only worth doing once the rest is in place.
Next in this series: Part 4, keeping plugins patched and giving every account only the access it needs.
Check your understanding
Was this helpful?
Sorry about that. What was missing?
Thanks for your feedback!

