WordPress security hardening: a practical guide

A practical WordPress security hardening guide covering logins, updates, file permissions, backups and server settings, in the order that stops attacks.

WordPress security hardening means reducing the ways an attacker can get into your site, and limiting the damage if they do. The core software is well maintained. Most break-ins I see come from three places: outdated plugins or themes, weak or reused admin passwords, and hosting accounts where one compromised site infects the others.

So hardening is mostly about discipline, not clever tricks. Keep software current, lock down logins, remove what you don't use, and make sure you can restore a clean copy in minutes. The steps below are in the order I apply them on client sites, starting with the changes that block the most attacks for the least effort.

If your site is already showing spam pages, strange redirects or a hosting warning, stop here and read how to clean a hacked WordPress site first. Hardening a site that still has a backdoor in it just locks the attacker inside with you.

Start with what attackers actually exploit

It helps to know what you are defending against. Nearly all WordPress attacks are automated. Bots scan millions of sites looking for a known vulnerable plugin version, or they try common usernames and leaked passwords against wp-login.php and xmlrpc.php. Nobody is personally targeting a small business site. A bot simply found a door that was open.

That shapes the priorities:

  • Vulnerable plugins and themes. This is the big one. A plugin with a known flaw and a public exploit gets hit within days.
  • Credential attacks. Brute force and credential stuffing (trying passwords leaked from other sites).
  • Neighbour infections. Several sites in one hosting account share the same file permissions. One abandoned test site can reinfect the live one.
  • Nulled software. "Free" copies of premium plugins very often contain hidden backdoors.

Everything else, like hiding the WordPress version or renaming the database prefix, is minor compared to these four.

Updates and plugin hygiene

Turn on automatic updates for minor WordPress releases (they are on by default) and decide on a policy for plugins. On most business sites I enable auto-updates for well-maintained plugins and handle big ones, like WooCommerce or page builders, manually after a quick check on a staging copy.

Then audit what is installed:

  1. Delete every deactivated plugin and unused theme. Deactivated code can still be reached directly and exploited.
  2. Keep one default theme (for example the current Twenty-something theme) as a fallback, and remove the rest.
  3. Check each plugin's "last updated" date on wordpress.org. If it has not been updated in a year or more, look for a maintained alternative.
  4. Replace anything nulled or downloaded from an unofficial site with a licensed copy.
  5. Fewer plugins means fewer doors. If a plugin does one small thing, consider whether a few lines of code or a theme setting can do it instead.

This is also covered in my WordPress maintenance checklist, because updates are a weekly habit rather than a one-off job.

Lock down logins and user accounts

Login protection is cheap and effective.

  • Strong unique passwords for every admin, stored in a password manager.
  • Two-factor authentication (2FA) for all administrator and shop manager accounts. Several free plugins offer this.
  • No "admin" username. Create a new administrator with a different name, log in as it, and delete the old one (assigning its content to the new user).
  • Least privilege. Content writers should be Editors or Authors, not Administrators. Remove accounts for former staff and agencies.
  • Limit login attempts. Many security plugins and most good hosts can rate-limit or block repeated failed logins.

If you don't use the mobile app or remote publishing tools, consider blocking xmlrpc.php. It is a common target for password guessing. Check first, though, because some plugins (Jetpack, for example) rely on it.

Harden wp-config.php and file permissions

A few lines in wp-config.php close off common abuse. This is the block I add on most sites:

// Stop file editing from the dashboard (Appearance > Theme File Editor)
define( 'DISALLOW_FILE_EDIT', true );

// Force SSL for the admin area
define( 'FORCE_SSL_ADMIN', true );

// Never show PHP errors to visitors on a live site
define( 'WP_DEBUG', false );
define( 'WP_DEBUG_DISPLAY', false );

DISALLOW_FILE_EDIT matters more than it looks. If an attacker gets an admin login, the built-in file editor is the quickest way to plant a backdoor. Turning it off removes that path. There is a stricter option, DISALLOW_FILE_MODS, which also blocks plugin installs and updates from the dashboard. I only use that when updates are handled through deployment.

Also make sure your security keys and salts are set and unique. You can generate fresh ones from the official WordPress salt generator and paste them in. Changing them logs everyone out, which is useful after a suspected breach.

For file permissions, the usual safe defaults on Linux hosting are:

ItemPermissionWhy
Folders755Owner can write, others can read and enter
Files644Owner can write, others can read
wp-config.php600 or 640Only the owner (and web server group) can read it

Never set anything to 777. If a plugin says it needs 777 to work, that is a sign of a bad plugin or a misconfigured server.

Server and hosting level protection

Some of the strongest protection sits outside WordPress.

  • Use a current PHP version that still receives security updates. Your host's control panel shows the options.
  • Isolate sites. If you run several sites, ideally each one has its own hosting account or its own system user, so one compromise doesn't spread.
  • Block PHP execution in uploads. The wp-content/uploads folder should only hold media. Many hosts let you block PHP there, or you can add a server rule. Uploaded shells are a common backdoor.
  • Web application firewall (WAF). A firewall at the DNS level (such as a CDN with WAF rules) or at the host stops a lot of malicious traffic before it reaches PHP. Plugin-level firewalls help too, but they run after WordPress has already started loading.
  • HTTPS everywhere with a valid certificate and HTTP redirected to HTTPS.
  • SFTP or SSH, not plain FTP. Plain FTP sends passwords unencrypted.

A good managed WordPress host handles much of this for you. Cheap shared hosting often doesn't, and that gap shows up when things go wrong.

Backups and monitoring

Hardening lowers the odds of a break-in. Backups decide how bad a break-in is.

A backup setup I'm comfortable with looks like this:

  • Daily automatic backups of files and database (more often for busy shops).
  • Stored off the server, for example in cloud storage, not only in the same hosting account.
  • At least 30 days of history, because infections are often discovered weeks later.
  • A test restore every few months. A backup you have never restored is a hope, not a plan.

For monitoring, set up uptime checks, file change alerts from a security plugin, and Google Search Console. Search Console will email you if Google detects malware or hacked content on your site, which is often the first warning a business owner gets.

A hardening checklist you can work through

Here is the order I'd do it in on a typical business site, in one sitting:

  1. Take a full backup and download it.
  2. Update WordPress core, all plugins and the active theme.
  3. Delete inactive plugins and unused themes.
  4. Review users, remove old accounts, fix roles.
  5. Change all admin passwords and enable 2FA.
  6. Add DISALLOW_FILE_EDIT and check debug settings in wp-config.php.
  7. Regenerate salts if you have any doubt about past access.
  8. Check file permissions and fix anything set to 777.
  9. Confirm PHP version and HTTPS redirect with your host.
  10. Install one reputable security plugin for login limiting, firewall and file change alerts.
  11. Set up off-site daily backups and do a test restore.
  12. Verify the site in Google Search Console if it isn't already.

One security plugin is enough. Running two or three at once usually causes conflicts and slows the site without adding real protection.

The short version

WordPress security hardening is not about obscure tweaks. Keep plugins updated and few, protect logins with strong passwords and 2FA, switch off the dashboard file editor, set sane file permissions, use decent hosting, and keep tested off-site backups. Do those well and you are ahead of the vast majority of sites the bots are scanning.

If you'd rather have someone do this properly, or your site is already acting strangely, I handle security clean-ups and hardening as part of my website bug fixing service. You can also get in touch and tell me what you're seeing.

Available for new projects

Need a hand with this?

Tell me what you need: a new site, a fix, a SaaS or an app. You'll get a clear plan and price within a day.

Start a project WhatsApp me