In this guide
If you only do five things
- Update everything, and turn on automatic updates where you can.
- Delete plugins and themes you don’t use.
- Use unique passwords and turn on two-factor login for every admin.
- Keep off-site backups, several versions back.
- Never install nulled (pirated) plugins or themes.
That alone would have prevented most of the infections I’ve cleaned. The rest of the list makes the site harder still to break into.
Software and plugins
1. Keep WordPress, plugins and themes updated
Most WordPress infections start with a plugin or theme that has a known security hole. Once a vulnerability is published, attackers scan the internet for sites that haven’t updated yet, often within days. Turn on automatic updates in Plugins for the plugins you trust, keep WordPress core updates on, and check the rest at least weekly.
2. Delete what you don’t use
A deactivated plugin is still on your server, and its files can still be attacked. The same goes for old themes. Keep one default theme as a fallback, and delete everything else you’re not using.
3. Never use nulled plugins or themes
“Free” copies of premium plugins are one of the most common sources of backdoors I find. The people who share them often add malicious code before uploading. If you need the plugin, buy the license. It’s far cheaper than a cleanup. More in nulled themes and plugins.
4. Choose plugins carefully
Before installing a plugin, check when it was last updated, how many sites use it, and whether its support forum has unanswered security reports. A plugin that hasn’t been updated in two years is a risk, however useful it is. For downloads from outside WordPress.org, use my plugin and theme malware check.
5. Keep PHP up to date
Ask your host which PHP version your site runs. Old PHP versions no longer receive security fixes. Most hosts let you switch versions in the control panel. Test the site after switching.
Logins and users
6. Use unique, strong passwords
Every admin needs a long, unique password, ideally from a password manager. A password reused from another site that was breached is one of the simplest ways in.
7. Turn on two-factor authentication
Two-factor login stops stolen passwords from being enough. Wordfence, Solid Security and other security plugins add it for free. Require it for every administrator and editor.
8. Limit administrator accounts
Give people the lowest role that lets them do their job. Authors don’t need to be admins. Remove accounts for people who no longer work on the site, and check the user list now and then for accounts you don’t recognize.
9. Limit login attempts
Bots try thousands of passwords against wp-login.php. Most security plugins include login rate limiting. Turn it on. The full list is in WordPress login security.
Backups
10. Keep off-site, versioned backups
A good backup turns a disaster into an inconvenience. Make sure your backups:
- are stored off your server, for example in cloud storage, so an attacker on the server can’t delete them;
- go back several weeks, because infections often start long before anyone notices;
- include both files and the database;
- have been tested: restore one to a staging site at least once.
Firewall and monitoring
11. Use a web application firewall
A firewall blocks common attacks before they reach WordPress. You can use a plugin firewall, such as Wordfence’s, or a cloud firewall, such as Cloudflare or Sucuri. A cloud firewall filters traffic before it reaches your server at all. If you use Cloudflare, start with these five free-plan firewall rules.
12. Monitor the site
- Run a malware scanner on a schedule, and actually read its alerts.
- Add your site to Google Search Console. It emails you if Google detects malware or spam on your site.
- Use a free uptime monitor, so you know quickly if the site goes down or changes.
Server and file settings
13. Disable the built-in file editor
WordPress lets admins edit theme and plugin code from the dashboard. Attackers who get into an admin account love this feature. Turn it off by adding this line to wp-config.php:
define( 'DISALLOW_FILE_EDIT', true );
14. Block PHP in the uploads folder
The uploads folder should only hold images and documents. Blocking PHP there stops many backdoors from running even if they’re uploaded. On Apache hosting, create a file called .htaccess inside wp-content/uploads with:
<FilesMatch "\.(php|phtml|phar)$">
Require all denied
</FilesMatch>
On Nginx, ask your host to add an equivalent rule. Test your site afterwards. A few plugins do store PHP files in uploads, and they’d need an exception. More in secure WordPress file uploads.
15. Use sensible file permissions and separate sites
Folders should be 755 and files 644. Use the strictest setting your host allows for wp-config.php (often 640 or 600). Never use 777. For the database side, see how to secure the WordPress database.
If you host several sites, keep them in separate hosting accounts, or at least separate system users. Otherwise, one infected site can infect all the others, and that’s one of the most common reasons I see infections keep coming back. More in secure WordPress hosting.
From my cleanup work: the most common story isn’t a clever attack. It’s a plugin that hadn’t been updated in a year, on a hosting account shared with three other old sites nobody remembered, with an admin password that had appeared in a data breach. Updates, separate hosting and two-factor login would each have stopped it on their own.
Want someone to do this for you?
This checklist is exactly what my security audit checks for ($70), and what the security care plan keeps in place month after month ($150/month).
If your site is already infected
Hardening a site that’s still infected doesn’t remove the infection. The attacker’s backdoor stays. Clean it first, by following my step-by-step malware removal guide or by having it cleaned professionally, and then work through this checklist.