· 8 min read · Mert Tati
How to Set Up Two-Factor Authentication (2FA) in WordPress: Step by Step
How to set up two-factor authentication in WordPress: what TOTP is, which authenticator app to use, recovery codes and what to do if you lose your phone.
Short answer: two-factor authentication (2FA) in WordPress asks for a 6-digit code at login, in addition to your password. The code comes from an authenticator app on your phone and changes every 30 seconds. To set it up, you activate a 2FA plugin; each user scans a QR code with the app from their own account, confirms it with a code and saves their one-time recovery codes somewhere safe. That way, even if your password leaks, nobody can get into your account.

What is two-factor authentication, and why do you need it?
A password is “something you know,” and once it leaks, anyone can know it: a data breach on another site, malware on your computer or a reused password is all it takes. Two-factor authentication adds “something you have”: your phone. Even if an attacker knows your password, they can't know the code showing on your phone at that moment.
This matters even more in WordPress, because an administrator account can do everything: install plugins, run code, see customer and order data. Losing an admin account usually means losing the whole site. That's why 2FA is one of the highest-return steps in securing a WordPress site.
What is TOTP? How is the code generated without internet?
Most WordPress 2FA plugins use the TOTP (Time-based One-Time Password) standard. During setup, a secret key is shared between the site and your phone; that's what the QR code carries. From then on, both sides use that key and the current time to calculate the same 6-digit code. The code refreshes every 30 seconds.
- No internet connection needed: the code is calculated on the phone, with no waiting for an SMS or a notification.
- The clock has to be right: if your phone's clock drifts by a few minutes, the codes won't match. Keep automatic time enabled on your phone.
- Small drifts are fine: a good implementation also accepts the codes from the previous and next periods, tolerating a few seconds of difference.
- The secret key should never be shown again: keeping a screenshot of the QR code means keeping the key itself.
Which authenticator app should you choose?
Because TOTP is an open standard, the app you choose makes no difference on the WordPress side. Google Authenticator, Microsoft Authenticator, Authy, 2FAS, Aegis (Android) and the code features in password managers like 1Password and Bitwarden all work the same way. When choosing, look at:
- Backup: can your codes move with you when you switch phones? Apps that offer cloud backup or encrypted export make life much easier if you lose your phone.
- Team use: for agency or company accounts, a shared password manager keeps the code from living on just one person's phone.
- Locking: being able to lock the app itself with a fingerprint or PIN is a good extra safeguard.
SMS or an authenticator app?
A code sent by SMS is better than nothing, but it isn't the best choice for WordPress. Attacks such as SIM cloning or porting your number to another line can intercept SMS codes. You'll also need a paid service to send SMS and have to send phone numbers outside your site. And when you're abroad or the signal is weak, codes can arrive late.
- SMS: easy to set up and familiar to users, but dependent on an external service, costly and exposed to SIM attacks.
- TOTP app: free, works offline and no data leaves your site; you need to scan a QR code during the initial setup.
- Hardware keys and passkeys: the strongest option, but every user needs a device and the plugin has to support it.
For most WordPress and WooCommerce sites, TOTP strikes the right balance: it's strong, free and runs entirely within your site.
How to set up 2FA in WordPress, step by step

- 1. Prepare: take a full backup of the site and confirm you can access wp-config.php via FTP or your hosting panel. This is your way out if you ever get locked out.
- 2. Install the plugin and turn on its 2FA module.
- 3. Go to your own account's 2FA screen and start the setup. You'll see a QR code and a setup key you can enter manually.
- 4. In your authenticator app, choose “add account” and scan the QR code. If you can't use the camera, enter the key by hand.
- 5. Enter the 6-digit code shown in the app on the site to confirm. 2FA shouldn't be enabled until it's verified; that way you won't lock yourself out with a misread QR code.
- 6. Download or print your recovery codes right away and store them in your password manager or a safe.
- 7. Test the flow by logging out and logging back in from a private window.
- 8. Make sure other administrators and editors set up 2FA on their own accounts too.
Recovery codes and losing your phone
The most common problem with 2FA isn't security, it's access: phones get lost, break or get reset. That's why one-time recovery codes should be generated during setup. Each code works only once; if you don't have your phone, you enter a code, and once you're in, you set up 2FA again on your new phone. When you're running low on codes, generate a new set and treat the old list as invalid.
- Lost your phone but have a recovery code: log in with the recovery code, turn 2FA off, set it up again on the new phone and generate new recovery codes.
- No recovery code, but there's another administrator: the other admin resets your 2FA from the Users list, and you set it up again.
- You're the only administrator and have no codes at all: you need an emergency route that temporarily disables 2FA via wp-config.php. Be sure to remove that line once you're back in.
What doesn't 2FA protect? Gaps to watch out for
2FA protects the login form. But WordPress has other authentication paths that work independently of it. xmlrpc.php accepts a username and password, and application passwords on the REST API don't ask for a second step by design, because they're built for apps and integrations. So after setting up 2FA, you should disable XML-RPC logins and, if you don't use them, application passwords as well. It's also important that wrong 2FA codes count toward your login attempt limit: for someone who already knows the password, the second step must not become a playground for unlimited guesses. We cover this separately in our post on blocking brute force attacks.
Keep one more thing in mind: 2FA makes account takeover harder, but it doesn't clean malware, monitor file changes or take backups. If your site has already been compromised, follow the steps in our my WordPress site was hacked guide first; for those jobs, you need a server-side scanning and backup solution.
Doing it all with one plugin: 2FA with Hushfort
The Hushfort WordPress security plugin brings the setup and recovery scenarios above together in its Two-Factor Authentication module:
- Works with every TOTP app, including Google Authenticator, Microsoft Authenticator and Authy.
- The QR code is generated in the browser, inside the plugin; the secret key is never sent to any external service. A setup key is also shown for manual entry.
- Each user sets it up from their own account's 2FA screen; enabling 2FA doesn't force it on other users. Administrators without 2FA see a persistent reminder notice.
- Setup isn't enabled until it's confirmed with a code.
- 10 one-time recovery codes are generated; they're shown only once and can be downloaded as a .txt file or printed. They're stored on the server as hashes, not plain text. You get a warning when you're running low, and you can regenerate them in one click.
- The secret key is stored encrypted in the database.
- Administrators can see who has 2FA enabled in the 2FA column of the Users list and reset it in one click.
- For emergencies, adding the line define( 'GATEKEEPER_2FA_DISABLE', true ); to wp-config.php temporarily turns off the second step.
- Wrong 2FA codes and failed application password attempts are counted by the Limit Login module's lockout counter.
The Surface Hardening module in the same plugin also closes the paths 2FA doesn't cover by disabling XML-RPC logins and, optionally, application passwords. If you'd like to hand off security maintenance for your store or company website, our team in Izmir can set all this up for you as part of our software and hosting service.
Frequently asked questions
Should I make 2FA mandatory for all users in WordPress? For privileged accounts such as administrators, editors and shop managers, yes, it should always be set up. For WooCommerce customers, mandatory 2FA is usually unnecessary friction; customers log in through the “My Account” page and have limited permissions.
Will I lock myself out if I set up 2FA? Not if you save your recovery codes and confirm your wp-config.php access in advance. Lockouts are almost always caused by recovery codes that were never saved.
I changed phones and my codes aren't on the new one. What should I do? If you still have the old phone, use the app's transfer feature. If not, log in with a recovery code, turn 2FA off, set it up again on the new phone and get new recovery codes.
Does changing WordPress salt keys affect 2FA? It does with solutions that encrypt the secret key using a key derived from the salts: once the salts change, old setups can't be decrypted and users have to set up 2FA again. If you regenerated your salt keys after a hack, check your 2FA setups too.
In short: WordPress 2FA protects your account even if your password leaks. Use a TOTP-based authenticator app, choose a solution that generates the QR code inside your site, confirm the setup with a code, keep your recovery codes safe and know your emergency route in advance. And separately close the XML-RPC and application password paths that 2FA doesn't cover.