How to secure your WordPress login
To secure the WordPress login, replace the admin user, limit login attempts, turn on two-factor authentication, protect wp-login.php and keep plugins and themes up to date. The wp-login.php page is a favourite target of bots that guess admin passwords around the clock. On shared hosting these attacks also use up your account limits, so the site slows down or hits a resource error. None of the steps below needs heavy plugins.
Check your site
-
Replace the admin user and set a strong password
Go to Users > All Users. If there is a user called admin, or one named after your domain, create a new administrator with a unique name, log in as that user and delete the old one, assigning its posts to the new account. Take a long password (16+ characters) from a generator instead of a word you can remember.
-
Limit login attempts
Out of the box, WordPress lets bots guess passwords without limit. A plugin such as Limit Login Attempts Reloaded locks an IP out for a while after a few failed tries. If your hosting runs Imunify360, it already filters some brute force before it reaches WordPress, and the plugin adds another layer on top.
-
Turn on two-factor authentication (2FA)
With 2FA, logging in takes a one-time code from an app (Google Authenticator, Authy) in addition to the password, so a leaked password alone does not let anyone in. The free Two-Factor or WP 2FA plugin does the job. Enable 2FA at least for every user with the administrator or editor role.
-
Hide or lock down wp-login.php
A plugin such as WPS Hide Login changes the login URL, so bots cannot find it at the default wp-login.php. Protecting the login at the server level is stronger: in cPanel, open Directory Privacy and password-protect the wp-admin folder, or, if your IP address is static, restrict wp-login.php to that address in .htaccess.
-
Add security headers in .htaccess
Security headers protect the login form from clickjacking (loading it in a hidden iframe) and from needless leaks. Add these lines to the .htaccess file in your site root:
Header always set X-Frame-Options SAMEORIGIN
Header always set X-Content-Type-Options nosniff
Header always set Referrer-Policy strict-origin-when-cross-origin
If the site runs on HTTPS, add Strict-Transport-Security as well. On LiteSpeed these lines work without extra modules. -
Keep WordPress updated and disable the file editor
Most sites are hacked through holes in outdated plugins and themes, and fewer through guessed passwords. Turn on automatic updates for core and plugins, and remove themes you do not use. Add define('DISALLOW_FILE_EDIT', true); to wp-config.php: it turns the editor off, so an attacker who gets into the dashboard still cannot edit theme code from there.
How to verify the result
Check that the old password, or a login without the 2FA code, no longer gets you into the dashboard, and that your IP is blocked after a few wrong attempts. To check the security headers on the login page, run it through the free SpoofLens headers checker: it grades them from A+ to F and shows which headers are still worth adding.
Tip: If you password-protect the whole wp-admin folder with Directory Privacy, make an exception for admin-ajax.php. Without it, forms, filters and other AJAX features on the public part of the site stop working.