Dev.to Security 🔐 Cybersecurity 👁 0 📖 8 min read

WordPress security hardening checklist: 20 steps that matter

TL;DR: Most known WordPress vulnerabilities are in plugins and themes, not in WordPress itself, and stolen or guessed passwords are the other common way in. So start there: update everything, delete what you don't use, a

TL;DR: Most known WordPress vulnerabilities are in plugins and themes, not in WordPress itself, and stolen or guessed passwords are the other common way in. So start there: update everything, delete what you don't use, and put two-factor authentication and login limits on every admin account. Then lock down wp-config.php, file permissions and the server, keep backups somewhere else, and check for changed files.

Originally published on devangwp.com.

I learned how sites break before I learned how to style them. A cyber-security internship came before most of my front-end work, and security audits and hardening have been part of my WordPress work ever since. This is the checklist I'd give any site owner, in order of impact: the first two sections deal with the most common ways in, and the rest make the damage small when something does get through.

WordPress's own hardening guide explains the background. This list is the practical order to do it in.

Before you start

  • Take a full backup of the files and the database, and make sure you know how to restore it.
  • Use a staging copy if you have one. A few steps here (blocking XML-RPC, stopping PHP in uploads, a Content Security Policy) can break a plugin that relies on what you're switching off. Test there first.
  • Some steps need server access (an .htaccess file on Apache, a config file on Nginx). If you're on managed hosting, your host can usually apply them for you.

Updates and what you install

1. Keep WordPress, plugins and themes updated

Most security releases fix flaws that have already been made public, so an out-of-date plugin is a documented way in that anyone can look up. Minor WordPress releases update automatically by default; leave that on. Turn on automatic updates for plugins you trust (from the Plugins screen), and test major updates on staging before they go live. Check for updates every week.

2. Delete plugins and themes you don't use

A deactivated plugin's files are still on the server, and they can still be requested directly. Deactivating isn't removing: delete it. Keep one default theme (a recent Twenty-something theme) as a fallback, and delete every other theme you aren't using.

3. Install only from sources you trust

Install from WordPress.org, or from the developer's own site for paid plugins. Never install "nulled" (pirated) premium plugins or themes: they're a common way to ship malware onto a site. Before installing anything, check when it was last updated and whether anyone still maintains it.

Logins and users

4. Strong passwords and two-factor authentication for every admin

Use a unique password from a password manager, plus two-factor authentication (an authenticator app) on every account that can publish content or change settings. WordPress doesn't include two-factor authentication itself, so it comes from a plugin (such as Two Factor, maintained by WordPress contributors) or from your single sign-on provider.

5. Limit login attempts

Out of the box, WordPress lets anyone try passwords on wp-login.php as often as they like. Limit failed attempts with a plugin, or better, rate-limit the login page at the server or the firewall so the guesses never reach PHP at all.

6. Give everyone the lowest role that does the job

Editors don't need to be Administrators. Every few months, go through the users list: remove people who have left, downgrade anyone with more access than they use, and make sure no account is called "admin". Fewer administrator accounts means fewer passwords that can unlock everything.

7. Turn off XML-RPC if nothing uses it

xmlrpc.php is an older remote API. One of its methods, system.multicall, lets an attacker try many passwords in a single request, which makes it a favourite target. The WordPress mobile app and Jetpack can use it, so check first. If nothing needs it, block it at the server:

# Apache: .htaccess in the site root
<Files xmlrpc.php>
  Require all denied
</Files>
# Nginx: inside your server block
location = /xmlrpc.php {
  deny all;
}

wp-config.php and files

8. Turn off the dashboard file editor

By default, any Administrator can edit theme and plugin PHP files from the dashboard. That turns one stolen admin password into code running on your server. Add this line to wp-config.php:

define( 'DISALLOW_FILE_EDIT', true );

9. Use unique keys and salts

wp-config.php holds eight secret keys and salts that protect login cookies. Make sure they're long and unique to this site. You can generate a fresh set from the official generator. Replacing them logs everyone out, which is exactly what you want after a suspected break-in.

10. Set file permissions correctly

Directories should be 755 and files 644. wp-config.php should be tighter: 640, or 440 or 400 if your host allows it. Nothing should ever be 777. Files should belong to your hosting account rather than the web server, except where WordPress has to write (usually wp-content/uploads).

# Run from the WordPress root folder. Check with your host first.
find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;
chmod 640 wp-config.php

11. Stop PHP from running in the uploads folder

wp-content/uploads should only ever hold media. If an attacker manages to upload a PHP file there (through a vulnerable form or plugin), blocking PHP in that folder stops the file from running.

# Apache: .htaccess inside wp-content/uploads
<FilesMatch "\.(php|phar|phtml)$">
  Require all denied
</FilesMatch>
# Nginx: put this before your main PHP location block
location ~* ^/wp-content/uploads/.*\.(php|phar|phtml)$ {
  deny all;
}

12. Keep errors off the page

Error messages can reveal file paths and details about your database. On a live site, debug mode should be off:

// Live site: no errors on the page
define( 'WP_DEBUG', false );

// Only while debugging: log errors, never display them,
// and write the log outside the public web folder
// define( 'WP_DEBUG', true );
// define( 'WP_DEBUG_DISPLAY', false );
// define( 'WP_DEBUG_LOG', '/home/account/logs/wp-debug.log' );

Since WordPress 5.1, WP_DEBUG_LOG accepts a file path. Use one: the default location, wp-content/debug.log, can be downloaded by anyone who guesses the address.

Server and HTTPS

13. HTTPS everywhere, with HSTS

Serve every page over HTTPS and redirect plain HTTP to it. Send a Strict-Transport-Security header, so browsers stop trying the insecure version at all. In Settings → General, make sure both the WordPress Address and the Site Address start with https://.

14. Send security headers

A few response headers close off whole classes of attack, such as another site loading yours in a frame to trick visitors into clicking (clickjacking), or a browser guessing a file's type. My own site, devangwp.com, sends these five on every response:

Strict-Transport-Security: max-age=63072000
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Referrer-Policy: strict-origin-when-cross-origin
Permissions-Policy: camera=(), microphone=(), geolocation=(), interest-cohort=()

A Content Security Policy is the strongest header and the hardest one on WordPress, because many plugins add inline scripts. Start it in report-only mode (Content-Security-Policy-Report-Only), fix what it reports, and enforce it once the reports are clean. The OWASP Secure Headers Project explains each header in detail.

15. Run a PHP version that still gets security fixes

Each PHP version stops receiving security fixes on a published date. PHP 8.2's security support ends on 31 December 2026, so aim for PHP 8.3 or newer, after testing your theme and plugins on it. The current dates are on php.net.

16. Put a firewall in front of the site

A web application firewall blocks known attack patterns and abusive traffic before they reach WordPress. It can come from your host, from a CDN in front of the site, or from a security plugin. The earlier in the chain it sits, the less load attacks put on your server.

Recovery and monitoring

17. Automatic backups, stored somewhere else, and a tested restore

Back up the database and files every day, and keep the backups off the server: if the server is compromised or lost, backups stored on it go with it. A backup you've never restored is a hope, not a plan, so restore one to staging every few months.

18. Check files against the official versions

WP-CLI can compare WordPress core, and plugins from WordPress.org, against the official checksums, and list any file that has been changed or added:

wp core verify-checksums
wp plugin verify-checksums --all

Anything flagged that you didn't change yourself deserves a closer look. Run both on a schedule, alongside a malware scanner.

19. Keep an activity log

Record logins, failed logins, new users, role changes, and plugin or theme installs. When something goes wrong, the log tells you when it started and which account was used.

20. Write down what you'll do when it happens

One page is enough: where the backups are, who has access to the hosting and the domain, and the order of work. Put the site into maintenance mode, keep a copy of the hacked files and logs, restore a clean backup, update everything, change every password and replace the keys and salts (step 9), then work out how they got in so it can't happen again.

Advice that's worth less than it sounds

  • Renaming the login page. It cuts down noise in the logs, but it's hiding, not protection. Login limits and two-factor authentication (steps 4 and 5) do the real work.
  • Changing the database table prefix. It doesn't stop SQL injection. Updating or removing the vulnerable plugin does.
  • Installing several security plugins. They overlap, slow the site down and can conflict with each other. One well-configured tool plus the server-level steps above is better than three.

How often to check

  • Every week: updates (step 1), and a quick look at the backups and the activity log.
  • Every three months: review users and roles, delete unused plugins, and test a restore.
  • When a staff member or agency leaves: remove their accounts, change any shared passwords, and replace the keys and salts.

Common questions

Is WordPress secure?

WordPress core has a dedicated security team and is patched quickly. Most problems come from outdated or abandoned plugins and themes, weak passwords, and hosting that isn't kept up to date, which are exactly what the steps above deal with.

Do I need a security plugin?

Not necessarily. A security plugin is a convenient way to get login limits, two-factor authentication, a firewall and scanning in one place, but each of those can also come from your host or your server. What matters is that every step is covered, not which tool covers it.

How do I know if my site has been hacked?

Common signs are admin users you don't recognise, new files in wp-content that you didn't add, spam pages or redirects that only show up in search results or on mobile, and a warning in Google Search Console under Security & Manual Actions. Step 18 catches changed files early, often before any of these appear.

More on how I work

Security audits and hardening are part of my WordPress work, shaped by a security background that came before my front-end work. See performance and security and the security hardening case study. Hiring for a WordPress role? Get in touch.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.