WordPress
WordPress Security Hardening That Keeps Your Site Fast
WordPress security hardening is the practice of reducing attack surface without adding the plugins and cron jobs that slow page loads. In my builds I start with core and plugin updates, explicit security headers, login protection, sane file permissions and tested backups, then measure LCP and INP so the hardening stays fast.
What WordPress security hardening actually covers
Security hardening is a set of defaults and small code changes that make a site harder to abuse. It is not a single plugin. I cover five areas on every build: keep core, themes and plugins current; send explicit HTTP security headers; reduce the brute-force surface at wp-login.php; lock down filesystem permissions and disable dangerous admin features; and keep backups that have been restored successfully at least once. Each item has a performance cost. A security suite that scans every request on a WooCommerce store adds PHP work to checkout, so I choose measures that run at the edge or at write time, not on every page view.
- Core, plugin and theme updates on a controlled schedule
- Security headers served at the edge or in Nginx/Apache config
- Login protection that does not run a database query per request
- Filesystem permissions and disabled file editing in wp-admin
- Off-site backups with a tested restore, not just a scheduled dump
Patch management without breaking a live site
Updates are the highest-value security work and the easiest to get wrong on a busy store. I run minor core updates automatically, hold major and plugin updates behind a staging copy, and keep a change log of what shipped and when. The staging copy matters because a security patch can change a hook a custom theme relies on. I use WP-CLI in the deployment step — `wp core update`, `wp plugin update --all`, then `wp cache flush` — so the same command runs the same way every time. After each update I smoke-test login, checkout and the contact form, and I check that no debug flag was left on from a previous debugging session.
Security headers that cost almost nothing
Security headers are the cheapest hardening per request because a proxy or web server emits them without touching PHP. I set Strict-Transport-Security with a sensible max-age once HTTPS is verified, X-Content-Type-Options: nosniff, Referrer-Policy: strict-origin-when-cross-origin, and a Content-Security-Policy that starts in report-only mode. On WordPress, the tricky header is CSP: inline scripts from page builders and analytics need nonces or carefully scoped allowances, so I collect violations first rather than shipping a policy that breaks the site. I also send X-Frame-Options: SAMEORIGIN unless a legitimate embed requires a different value. Adding these at the server or CDN layer keeps TTFB unchanged.
- Strict-Transport-Security after HTTPS is confirmed end to end
- X-Content-Type-Options: nosniff
- Referrer-Policy: strict-origin-when-cross-origin
- Content-Security-Policy in Report-Only mode before enforcement
- X-Frame-Options: SAMEORIGIN for admin pages
Login protection without a per-request tax
Login attacks target wp-login.php and xmlrpc.php, but most defensive plugins hook into every request to decide whether to intervene. I prefer controls that act only on the login path: server-level rate limiting on POST /wp-login.php, a CAPTCHA or a honeypot field on the login form, and disabling XML-RPC if nothing needs it. I never show a hint about which field failed, and I keep the default admin username out of production. For teams, enforced two-factor authentication and unique accounts beat a shared login. This approach keeps cached page responses identical for every visitor, so it does not undo full-page caching or add work to the front end.
- Rate limit POST requests to wp-login.php at the server or CDN
- Disable XML-RPC when no external client needs it
- Two-factor authentication for every editor and administrator account
- No shared accounts and no default admin username
File permissions and the settings I disable
WordPress can be hardened at the filesystem without touching runtime speed. Files should be 644 and directories 755; wp-config.php can be 600 where the hosting setup allows it. Ownership should belong to the deploy user, not the web server account, so a compromised PHP process cannot rewrite theme files. I add define('DISALLOW_FILE_EDIT', true); and usually define('DISALLOW_FILE_MODS', true); on managed deployments, with updates handled through the deploy pipeline instead. I also remove default sample files, keep uploads free of executable PHP, and disable directory indexing. None of this runs on a page view, so TTFB and LCP stay put.
- Files 644, directories 755, wp-config.php 600 where supported
- Ownership by the deploy user, not the web server account
- DISALLOW_FILE_EDIT and DISALLOW_FILE_MODS in wp-config.php
- Directory indexing off and no executable PHP in uploads
Backup discipline: the part people skip
A backup is only useful if a restore has actually worked. I keep automated off-site copies of the database and uploads, with retention long enough to recover from a bad update discovered days later — typically 14 to 30 daily copies plus weekly ones. Backups live outside the web root and outside the same account as the site, so a compromised credential cannot delete them. I test a restore on staging every month and record how long it took. On WooCommerce stores I also define an order-recovery point: the last verified pre-incident database dump plus payment-provider records. As a freelancer in Mymensingh, Bangladesh working with clients across time zones, I have learned that a documented restore runbook matters more than a dashboard full of green ticks.
Measure the cost, then keep the wins
Hardening should not be judged by the number of security plugins installed. I record LCP, INP and TTFB before the changes and after them, on the same throttled profile, and I keep any measure that does not move those numbers. Header changes belong in server config, login rules belong on the login path, and file permissions belong in the deploy step. Where a security feature would add a database query to every rendered page, I look for a cache-friendly equivalent first. That is the approach I use as Saif Al Jahan on webdev-saif.com and in client builds: fewer moving parts, explicit configuration, and a performance budget that stays intact.
- Record LCP, INP and TTFB before and after hardening
- Keep security rules out of the cached page path
- Prefer server and CDN configuration over PHP middleware
- Re-check Core Web Vitals after every update
Frequently asked questions
Does WordPress security hardening slow down a site?
No, not when the work is placed correctly. Security headers served by Nginx, Apache or a CDN cost nothing per PHP request, and file-permission changes never run at render time. The slowdown usually comes from all-in-one security plugins that scan every request. I keep login rules on the login path and measure LCP and INP before and after each change so any regression is visible immediately.
Which WordPress updates should be automatic?
I let minor core updates and security releases apply automatically, because they rarely change custom code behaviour. Major core versions and plugin updates go to staging first, then to production through WP-CLI after a smoke test of login, checkout and forms. Keeping a short change log makes it obvious which patch caused a regression.
What file permissions should WordPress use?
Files at 644 and directories at 755 are the safe default; wp-config.php can be 600 if the host supports it. Files should be owned by the deploy user rather than the web server account, so a compromised PHP process cannot rewrite theme code. I also set DISALLOW_FILE_EDIT to true on managed sites.
Do I still need a security plugin?
Not necessarily. Headers, file permissions and server-level rate limiting do more than most plugins and cost less. I use a plugin only when it fills a specific gap, such as two-factor authentication for a team, and I disable its scanner and firewall modules if they add work to cached requests. Measure before keeping it.
How often should I test a WordPress backup?
Monthly, on a staging copy, not just when something breaks. A backup you have never restored is an assumption. I keep 14 to 30 daily database and upload copies off-site, run a restore on staging every month, and record the time it took. That runbook is what actually saves an incident.