WordPress Security Hardening and Choosing a Plugin
Practical WordPress security hardening in order of impact: updates, logins, wp-config.php, server rules, headers, backups and how to pick a security plugin.
· updated · 9 min read
In this article8 sections
Many hacked WordPress sites are not hit by clever attacks. They run an outdated plugin with a known vulnerability, or an admin account with a reused password, and automated scanners find them.
So hardening WordPress is mostly about removing those easy wins: fewer and fresher plugins, strong logins, a locked-down wp-config.php, sensible server rules and backups you can actually restore. This guide covers those steps in order of impact, then explains how to choose a security plugin without installing three that fight each other.
Start with updates and fewer plugins
Every plugin and theme is code from someone else running with full access to your site. The biggest single improvement on most sites is having less of it, and keeping the rest current.
- Turn on automatic updates for minor core releases (on by default) and for plugins you trust. WordPress has supported auto-updates per plugin from the Plugins screen since version 5.5.
- Delete what you do not use. A deactivated plugin is still files on the server, and vulnerable files can still be reached directly. Deactivate and delete.
- Check maintenance before you install. Look at when the plugin was last updated, whether the author answers support threads, and whether it is tested with your WordPress version. A plugin that has not been touched in years is a liability, even if it works.
- Avoid nulled themes and plugins. Pirated premium plugins are a classic way malware gets onto sites, often with a backdoor already included.
- Keep PHP current. Old PHP versions stop getting security fixes. Your host's panel shows which version you run.
Big plugin updates and PHP upgrades should go through a staging copy of the site first, so a broken update never reaches visitors.
Lock down user accounts and logins
Stolen or guessed credentials are the other main way in. Most of this costs nothing.
- Give every person their own account. Shared logins make it impossible to know who did what or to remove one person's access.
- Use the lowest role that works. An editor who writes posts does not need Administrator. Review the user list a few times a year and remove people who have left.
- Use long, unique passwords from a password manager. Reuse is the real danger, because a password leaked from another service will be tried on your login form. The password security guide goes deeper.
- Require two-factor authentication for every account that can install plugins or edit code. A small dedicated 2FA plugin is enough if you do not want a full security suite.
- Limit login attempts. Rate limiting at the server, the CDN or with a plugin stops brute force attempts from running at full speed.
Changing the login URL from /wp-login.php reduces log noise from bots, but it is obscurity rather than protection. Do it if you like quieter logs, never instead of 2FA.
Harden wp-config.php
wp-config.php holds database credentials and security keys, and it also controls a few switches that close common attack paths. Add these above the comment near the end of the file that tells you to stop editing:
define( 'DISALLOW_FILE_EDIT', true );
define( 'FORCE_SSL_ADMIN', true );
define( 'WP_DEBUG_DISPLAY', false );
DISALLOW_FILE_EDIT removes the built-in theme and plugin editor, so a stolen admin login cannot be turned into code execution with a few clicks. FORCE_SSL_ADMIN keeps logins and admin sessions on HTTPS. Keeping debug display off stops error messages from leaking file paths.
There is a stricter option, DISALLOW_FILE_MODS, which also blocks installing and updating plugins from the dashboard. Only use it if updates are handled another way, for example through deployments or WP-CLI, or you will end up with an unpatched site.
Two more things worth doing:
- Rotate the security keys and salts after a suspected compromise or when someone with server access leaves. New keys log out every session. WordPress.org offers a generator linked from the official hardening docs.
- Protect the file itself. WordPress looks for
wp-config.phpone folder above the web root, so you can move it out of the public directory. Otherwise set strict permissions such as640or600, depending on how your server runs PHP.
Server rules: permissions, uploads and XML-RPC
File permissions
The usual baseline is 755 for folders and 644 for files, owned by the account PHP runs as. Never use 777. If a plugin asks for it, the plugin is the problem.
No PHP in the uploads folder
The uploads folder only needs images and documents. If an attacker manages to upload a PHP file there, blocking execution stops it from running. On Apache 2.4, put this in wp-content/uploads/.htaccess:
<FilesMatch "\.phpquot;>
Require all denied
</FilesMatch>
On Nginx, add a rule in the server block, above the main PHP location block, because Nginx uses the first regex location that matches:
location ~* /wp-content/uploads/.*\.php$ {
deny all;
}
XML-RPC
xmlrpc.php is an old remote API. It is a popular target for brute force because one request can try many passwords. If you do not use Jetpack or another service that needs it, block it at the server or the CDN. Test after you block it, since some integrations depend on it without saying so.
User enumeration
WordPress exposes author usernames through /?author=1 redirects and the REST API users endpoint. That alone is not a hole, but it gives attackers half of a login. Make sure display names differ from usernames, and restrict the users endpoint to logged-in users if nothing public needs it.
HTTPS, security headers and the edge
Run the whole site on HTTPS and redirect HTTP to it. Then add a few response headers at the server or CDN level:
Strict-Transport-Securityso browsers only use HTTPS for your domain.X-Content-Type-Options: nosniffto stop MIME type guessing.Referrer-Policy: strict-origin-when-cross-originto limit what leaks to other sites.X-Frame-Options: SAMEORIGINor aframe-ancestorsrule to block clickjacking.
A full Content Security Policy is the strongest header and the hardest one on WordPress, because themes and plugins load scripts from all over the place. Start in report-only mode. The Content Security Policy guide explains how.
A CDN or reverse proxy in front of the site adds a useful layer. It can absorb bot traffic, rate limit the login page and hide the origin server's IP address. At Walldy we run DNS through Cloudflare, and the Cloudflare setup guide covers the basic security settings.
How to choose a security plugin
Security plugins are useful, but they are not all the same kind of tool, and stacking several usually causes conflicts. Decide which layers you need first, then pick the plugin.
The main types
- Endpoint firewall and scanner suites. These run inside WordPress, filter requests in PHP before your site handles them, scan files for malware and usually bundle login protection. Wordfence and Solid Security (formerly iThemes Security) are well-known examples. Strength: deep WordPress context. Cost: they use your server's resources.
- Cloud firewalls. These filter traffic before it reaches your server, usually by routing your domain through the vendor's network. Sucuri works this way, and a CDN like Cloudflare can fill a similar role. Strength: bad traffic never touches your server. Cost: you change DNS, and the origin must be locked down so it cannot be reached directly.
- Vulnerability monitoring and virtual patching. Tools like Patchstack warn you when a plugin you run has a known vulnerability, and some block exploit attempts until you can update.
- Single-purpose plugins. Two-factor login, login rate limiting or an activity log. Good when your host or CDN already handles the firewall.
What to look for
- Active maintenance. A security plugin that is not updated often is worse than none.
- No overlap. Two firewalls or two malware scanners on one site double the load and the false positives. Pick one per layer.
- Fit with your host. Many managed WordPress hosts already run a firewall and malware scanning, and some block certain security plugins. Check before you install.
- Performance. Scheduled scans and request logging can be heavy on small hosting plans. Test on staging and watch response times.
- Where alerts go. Alerts sent to an inbox nobody reads protect nobody. Route them to someone who acts on them.
- Free versus paid tiers. Some vendors deliver new firewall rules or malware signatures to paying customers first. Read what the free tier actually includes rather than assuming.
- Cleanup and support. If you get hacked, a vendor that offers malware cleanup can be worth more than any feature list.
There is no single best plugin. A small brochure site behind a CDN with 2FA may only need a 2FA plugin. A WooCommerce store on its own server may need an endpoint firewall, scanning and activity logging.
Backups, monitoring and a recovery plan
Hardening lowers the odds. Backups decide how bad a bad day gets.
- Keep backups off the server. A backup stored next to the site disappears with it. Automate daily backups of files and database to separate storage, and keep several versions. The WordPress backup strategies guide covers the details.
- Test a restore. Restore to staging a few times a year. That is the only way to know the backup works.
- Log admin activity. An activity log shows who installed a plugin or created a user, which is the first thing you need after an incident.
- Write down the recovery steps. Who has hosting access, where backups live, how to put the site in maintenance mode, how to rotate passwords and keys.
The official WordPress hardening documentation is worth reading once alongside this guide.
Frequently asked questions
What is the most important WordPress security step?
Keeping core, plugins, themes and PHP updated, and deleting plugins you do not use. Known vulnerabilities in outdated plugins are one of the most common ways WordPress sites are compromised.
Do I need a security plugin for WordPress?
Not always. If your host or CDN already provides a firewall and malware scanning, a 2FA plugin and good update habits may be enough. On self-managed hosting, one well-maintained security suite is usually worth it.
Can I use two WordPress security plugins at the same time?
Avoid running two plugins that do the same job, such as two firewalls or two malware scanners. They slow the site down and can block each other. Combining one suite with a single-purpose plugin for something it lacks is fine.
Does hiding the WordPress login page improve security?
It cuts down automated login attempts and log noise, but anyone determined can still find the login. Treat it as a minor extra on top of strong passwords, 2FA and rate limiting.
Should I disable XML-RPC in WordPress?
Yes, if nothing on your site uses it. Jetpack and some apps and older integrations use it, so test after blocking it.
What should I do if my WordPress site gets hacked?
Take the site offline or into maintenance mode, change all passwords and rotate the security keys, then restore a clean backup from before the compromise or have the site professionally cleaned. Afterwards, find and fix the way in, or it will happen again.
- WordPress
- Security
- Hardening
- Plugins

Written by Pontus Henriksson
Co-founder and CEO of Walldy in Sundsvall. I have built for the web since I was fourteen, tested games for studios like Netflix and Bungie since 2021, and write about what I use in real projects.
Liked this? Get the next one.
New Claude skills, kits and what I learn building AI for small businesses. Not often, only when it is worth sending. Unsubscribe with one click.