WordPress Security: 12 Steps to Protect Your Site

WordPress Security: 12 Steps to Protect Your Site

WordPress runs a very large share of the sites on the internet. That popularity also makes it attractive to attackers: a single vulnerability in one plugin can affect tens of thousands of sites at once. The good news is that the vast majority of compromised WordPress sites are not taken over by sophisticated attacks, but through paths that a few simple measures would have blocked.

Updates

1. Keep plugins and themes up to date

The most common reason WordPress sites get compromised is plugins with known vulnerabilities. Automated attacks start within hours of a vulnerability being published. Turn on automatic updates for plugins or check at least once a week.

2. Delete plugins and themes you do not use

A deactivated plugin can still be a risk as long as its files remain on the server. Delete anything you do not use completely. Keep just one default theme as a fallback.

3. Choose plugins carefully

Avoid plugins that have not been updated for a long time, have few users or were downloaded from outside the official directory. Premium plugins and themes offered "for free" (nulled) very often contain backdoors.

4. Update WordPress core and your PHP version

A PHP version that has reached end of life no longer receives security updates. Switch to a supported version from your hosting panel.

Access

5. Reduce the number of administrator accounts

Not every editor needs to be an administrator. Give users only the role they need to do their job and remove the accounts of departing staff immediately.

6. Use strong passwords and two-factor authentication

Your login page faces automated password attempts every day. Use unique, long passwords on all admin accounts and enable two-factor authentication with a plugin. More: password security guide.

7. Limit login attempts

Temporarily blocking an IP address after a number of failed attempts makes brute-force attacks largely ineffective. If you do not use it, disable access to xmlrpc.php as well.

Server and configuration

8. Disable file editing from the dashboard

Adding define('DISALLOW_FILE_EDIT', true); to wp-config.php makes it harder for an attacker to inject malicious code into theme or plugin files from the dashboard, even if an admin account is compromised.

9. Check file permissions and the uploads folder

The wp-config.php file must not be readable by others, and PHP execution should be blocked in the uploads folder. Attackers often gain a permanent foothold by uploading a web shell into that folder.

10. Enable HTTPS and security headers

Your site should run only over HTTPS. Security headers such as HSTS, X-Frame-Options and Content-Security-Policy add protection against browser-based attacks.

Preparation

11. Take regular backups and store them off the server

If your backups live only on the same server, an attacker who takes over the server can delete them too. Back up your files and database regularly to a different location and test a restore at least once. For a backup strategy, see our article on the 3-2-1 rule.

12. Monitor changes

A security plugin that monitors file changes and admin logins lets you notice an attack within minutes instead of weeks. Registering with Google Search Console also means you get a warning when malicious content is added to your site.

If your site has already been hacked

If you see unknown redirects, gambling or pharmacy spam, new admin accounts or a "This site may be hacked" warning in Google, deleting the visible malicious content is not enough. If the backdoors the attacker left behind remain, the site will be compromised again within days. We explain the steps to follow in My website has been hacked: what should I do?

If you want your site, especially custom-built plugins and forms, tested through an attacker's eyes, take a look at our web application penetration testing service. If you are under attack, we provide same-day incident response.

2DR

Cyber Security Team

Articles by the 2DR team, working in penetration testing, incident response and personal digital security.

LinkedIn profile