
WordPress core is secure when it is kept up to date. Most hacked WordPress sites are broken into through outdated or pirated plugins and themes, weak or reused passwords, and poorly configured hosting. Hardening means closing those doors one by one: updates, strong logins with two-factor authentication, least-privilege user roles, a web application firewall, correct file permissions, locked-down configuration and tested off-site backups. This guide walks through 15 practical steps, with the exact code and settings, in the order that gives the most protection first. This guide explains WordPress security step by step.
- Updates, two-factor login and off-site backups prevent or fix the vast majority of WordPress hacks.
- Never install nulled (pirated) themes or plugins; they are a leading source of malware.
- Give every person their own account with the lowest role they need.
- Security plugins help, but they cannot replace good hosting, updates and backups.
WordPress security: how WordPress sites actually get hacked
| Attack route | What happens | Main defence |
|---|---|---|
| Vulnerable plugin or theme | A known flaw lets attackers upload files or create admin users | Updates, fewer plugins, firewall |
| Brute force and credential stuffing | Bots try leaked passwords on wp-login.php and XML-RPC | Unique passwords, 2FA, login limits |
| Nulled software | Pirated premium plugins arrive with backdoors pre-installed | Licensed downloads only |
| Compromised hosting account | Weak cPanel or FTP password, or another infected site on the same account | 2FA on hosting, SFTP, account isolation |
| Stolen admin session | Malware on the admin's own computer steals cookies | Clean devices, short sessions, 2FA |
WordPress security: 1. Keep WordPress, plugins, themes and PHP updated
Most real-world attacks target flaws that were already fixed in an update. Turn on automatic updates for minor core releases (on by default) and for trusted plugins under Plugins → Enable auto-updates. For business-critical sites, test major updates on a staging copy first. Run a supported PHP version (8.2 or newer at the time of writing), which you can change in your hosting panel.
WordPress security: 2. Delete unused plugins and themes
A deactivated plugin's files are still on the server and can still be exploited. Delete anything you do not use, and keep only one default theme as a fallback. Fewer plugins also means a faster site; see our essential plugins list.
WordPress security: 3. Use only licensed, maintained software
Download plugins only from WordPress.org or the developer's own site. Before installing, check the last update date, active installs and support forum. A plugin that has not been updated for over a year is a risk.
WordPress security: 4. Strong unique passwords and two-factor authentication
Use a password manager to give every account a long, unique password. Then add two-factor authentication (2FA) for all administrators and editors with a plugin such as Wordfence Login Security, Two Factor or the 2FA built into your security plugin. Use an authenticator app rather than SMS where possible.
WordPress security: 5. Use least-privilege user roles
| Role | Give it to |
|---|---|
| Administrator | One or two trusted owners or developers only |
| Editor | Staff who manage all posts and pages |
| Author | Writers who publish their own posts |
| Shop Manager | WooCommerce staff handling orders and products |
Never share one admin login between people. Remove accounts as soon as staff or agencies stop working on the site, and do not use "admin" as a username.
6. Limit login attempts and protect wp-login.php
Rate-limit failed logins with your security plugin or host. Changing the login URL with a plugin such as WPS Hide Login reduces bot noise, but treat it as an extra, not a replacement for 2FA. On Apache you can also restrict the login page to your office IP:
<Files wp-login.php>
Require ip 203.0.113.10
</Files>
Only use IP restriction if your IP is fixed, or you will lock yourself out.
7. Disable XML-RPC if you do not need it
XML-RPC (xmlrpc.php) lets apps talk to WordPress, but attackers use it to try hundreds of passwords in one request. If you do not use the WordPress mobile app or Jetpack, block it:
<Files xmlrpc.php>
Require all denied
</Files>
8. Add a web application firewall (WAF)
A WAF blocks known attack patterns before they reach WordPress. Options include:
- DNS-level: Cloudflare (free plan includes basic protection and managed rules on paid plans), Sucuri.
- Plugin-level: Wordfence, Solid Security, which run inside WordPress.
- Host-level: many managed WordPress hosts include Imunify360 or a ModSecurity rule set.
DNS-level firewalls stop bad traffic earliest and also act as a CDN.
9. Harden wp-config.php
Add these lines above /* That's all, stop editing! */:
// Block the built-in theme and plugin file editors
define( 'DISALLOW_FILE_EDIT', true );
// Force HTTPS for logins and the dashboard
define( 'FORCE_SSL_ADMIN', true );
// Never show PHP errors to visitors on a live site
define( 'WP_DEBUG', false );
define( 'WP_DEBUG_DISPLAY', false );
Also make sure the security keys and salts are unique; generate fresh ones from the official WordPress salt generator, which also logs everyone out. If your host allows it, move wp-config.php one folder above the web root.
DISALLOW_FILE_MODS goes further and blocks all plugin and theme installs and updates from the dashboard. Only use it if updates are handled another way, such as by your developer through Git or WP-CLI, or the site will stop receiving security updates.10. Set correct file permissions
| Item | Permission |
|---|---|
| Folders | 755 |
| Files | 644 |
wp-config.php | 440 or 400 |
Never use 777. If a plugin says it needs it, the hosting setup is wrong. On a server with SSH access:
find /path/to/site -type d -exec chmod 755 {} \;
find /path/to/site -type f -exec chmod 644 {} \;
chmod 440 /path/to/site/wp-config.php
11. Stop PHP from running in the uploads folder
Attackers often upload a PHP backdoor disguised as an image. Create wp-content/uploads/.htaccess with:
<FilesMatch "\.(php|phtml|php\d|phar)$">
Require all denied
</FilesMatch>
12. Add security headers
Security headers tell browsers to block common attacks such as clickjacking and content sniffing. Add them in .htaccess, your host or Cloudflare:
<IfModule mod_headers.c>
Header always set X-Content-Type-Options "nosniff"
Header always set X-Frame-Options "SAMEORIGIN"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
Header always set Permissions-Policy "camera=(), microphone=(), geolocation=()"
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
</IfModule>
Only enable HSTS once the whole site and all subdomains work on HTTPS; see our SSL guide. A Content-Security-Policy gives the strongest protection but needs careful testing, because it can block legitimate scripts.
13. Secure the hosting account
- Turn on 2FA for your hosting panel, domain registrar and Cloudflare account. Whoever controls these controls the site.
- Use SFTP or SSH keys instead of plain FTP.
- Give each website its own hosting account or isolated user, so one infected site cannot reach the others.
- Use a unique database user and password per site, with a table prefix other than
wp_on new installs.
14. Keep off-site backups and test restores
Backups are what save you when every other defence fails. Keep daily backups of files and database, store copies away from the server (cloud storage or your host's separate backup system), and test a restore every few months. Our WordPress backup guide explains the 3-2-1 rule step by step.
15. Monitor for changes and malware
- Enable file-change alerts and malware scans in your security plugin.
- Turn on an activity log (for example WP Activity Log) to see who changed what.
- Set up uptime monitoring so you know within minutes if the site goes down or is defaced.
- Check Search Console's Security issues report; Google warns you there if it detects malware or hacked content.
WordPress security: signs your WordPress site has been hacked
- Unknown administrator accounts in Users.
- Visitors on mobile, or from Google, redirected to spam or gambling sites.
- Japanese or pharmaceutical spam pages appearing in a
site:yourdomain.comGoogle search. - New PHP files with random names in
wp-content/uploadsor the site root. - Your host suspending the account for sending spam or high resource use.
- A red "Deceptive site ahead" warning in Chrome.
If you see these, put the site into maintenance mode, change all passwords (hosting, database, WordPress, FTP), restore a clean backup or have the site professionally cleaned, update everything, then request a review in Search Console.
WordPress security: quick hardening checklist
| Task | How often |
|---|---|
| Update core, plugins and themes | Weekly |
| Review user accounts and roles | Monthly |
| Check backups ran and are stored off-site | Weekly |
| Test a full restore | Every 3 months |
| Review security plugin and firewall alerts | Weekly |
| Check PHP version and remove unused plugins | Every 3 months |
WordPress security: frequently asked questions
Is WordPress secure enough for a business website?
Yes. WordPress core has a dedicated security team and fast updates. Problems almost always come from outdated extensions, weak logins and cheap, poorly managed hosting.
Do I need a security plugin?
For most sites, yes, for 2FA, login limits, file scanning and a firewall. Use one security plugin, not several, because they conflict and slow the site down.
Does hiding the WordPress version help?
Very little. Attack bots try exploits regardless of the version shown. Spend the time on updates and 2FA instead.
How much does WordPress malware removal cost?
It depends on how badly the site is infected and whether clean backups exist. Prevention through a maintenance plan is almost always cheaper than cleanup.
Related guides: How to Move WordPress to a New Host Without Downtime, There Has Been a Critical Error on This Website and How to Update the PHP Version of Your WordPress Site Safely.
For official guidance, see the official WordPress documentation.
Want your site hardened and monitored?
Our maintenance and support plans cover updates, backups, firewall setup, monitoring and malware cleanup for WordPress sites. See also our WordPress development service, or contact us for a security check.
Written by the ItsWebExpert team, a web design and development company in Karachi building websites, online stores and apps for businesses across Pakistan.
Ask a Question on WhatsApp