#### 🔐 WordPress Security — Complete Guide

#### 1. Keep Everything Updated
This alone prevents ~80% of hacks.
- WordPress core — update immediately when new versions release
- All plugins — delete ones you don't use, update the rest
- All themes — delete unused themes (keep only active + one default)
- PHP version — use PHP 8.1 or 8.2 (set in cPanel/SiteGround)

#### 2. Strong Login Security
##### Use strong passwords
- Minimum 16 characters, mix of letters/numbers/symbols
- Never reuse passwords across sites
- Use a password manager (Bitwarden, 1Password)
##### Change the default admin username
    Never use admin as your username. Create a new admin user with a different name, then delete the admin account.
##### Enable Two-Factor Authentication (2FA)
Install Wordfence or WP 2FA plugin. Every admin login requires a second verification code from your phone.
##### Limit login attempts
Install Limit Login Attempts Reloaded — blocks IPs after 3–5 failed login attempts. Stops brute force attacks completely.
##### Change the login URL
    By default WordPress login is at /wp-login.php — hackers know this. Use WPS Hide Login plugin to change it to something custom like /my-secret-door.

#### 3. Harden wp-config.php
    Add these lines just above /* That's all, stop editing! */:
php
// Disable file editing from wp-admin
define('DISALLOW_FILE_EDIT', true);

// Disable file modifications entirely (updates too)
define('DISALLOW_FILE_MODS', false); // set true only on fully stable sites

// Force SSL for admin and logins
define('FORCE_SSL_ADMIN', true);

// Limit post revisions
define('WP_POST_REVISIONS', 5);

// Disable error display on frontend
define('WP_DEBUG', false);
define('WP_DEBUG_DISPLAY', false);

// Move wp-content (optional, advanced)
// define('WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/content');
Also make sure your security keys/salts are properly set (not the placeholder text) — generate fresh ones at https://api.wordpress.org/secret-key/1.1/salt/
    Set wp-config.php file permission to 600 (only owner can read/write).

#### 4. Secure .htaccess
    Add these rules to your .htaccess file in public_html/:
apache
# Protect wp-config.php
<Files wp-config.php>
order allow,deny
deny from all
</Files>

# Protect .htaccess itself
<Files .htaccess>
order allow,deny
deny from all
</Files>

# Block access to xmlrpc.php (common attack vector)
<Files xmlrpc.php>
order deny,allow
deny from all
</Files>

# Disable directory browsing
Options -Indexes

# Block suspicious query strings
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule .* index.php [F,L]

# Block author scanning
RewriteCond %{QUERY_STRING} ^author=([0-9]*)
RewriteRule .* /? [L,R=301]

#### 5. Install a Security Plugin
Pick one of these — don't install multiple security plugins:
| Plugin | Best For |
| Wordfence Security | Most complete — firewall + scanner + 2FA + login protection |
| Solid Security (iThemes) | Good for beginners, many hardening options |
| Sucuri Security | Excellent scanner + activity log |
| All-In-One Security | Free, lightweight, good for basics |

Wordfence is the most popular. After installing:
- Enable the Web Application Firewall (WAF)
- Run a full malware scan
- Enable 2FA
- Turn on login security (limit attempts, strong passwords)
- Set up email alerts for suspicious activity

#### 6. Use SSL (HTTPS)
Your site must use HTTPS. On SiteGround this is easy:
- Site Tools → Security → SSL Manager
- Install Let's Encrypt certificate (free)
- Site Tools → Security → HTTPS Enforce → turn ON
- In WordPress admin → Settings → General → change both URLs to https://

#### 7. Database Security
- Change the table prefix from wp_ to something random like x7k_ — do this during installation or with a plugin like Brozzme DB Prefix
- Use a strong database password — change it in cPanel MySQL and update wp-config.php
- Never give the DB user more permissions than needed — only SELECT, INSERT, UPDATE, DELETE

#### 8. File & Folder Permissions
Set correct permissions via File Manager or FTP:
Folders:          755
Files:            644
wp-config.php:    600
.htaccess:        644
uploads folder:   755
    No PHP files should exist in /wp-content/uploads/ — block PHP execution there by adding a .htaccess file inside the uploads folder:
apache
<Files "*.php">
Require all denied
</Files>

#### 9. Disable XML-RPC
XML-RPC is an old API that's frequently exploited for brute force attacks. Unless you use the WordPress mobile app or Jetpack, disable it.
    Add to .htaccess:
apache
<Files xmlrpc.php>
order deny,allow
deny from all
</Files>
Or use a plugin: Disable XML-RPC (tiny, free plugin).

#### 10. Regular Backups
Backups are your last line of defense. Even a perfectly secured site can get hacked.
- SiteGround: Site Tools → Backups — they keep 30 days of daily backups automatically ✅
- Install UpdraftPlus plugin as an extra backup to Google Drive or Dropbox
- Test your backups periodically by actually restoring one

#### 11. Activity Logging
Know what's happening on your site:
- Install WP Activity Log plugin — logs every login, file change, plugin install, settings change
- If you're ever hacked again, the log tells you exactly when and how

#### 12. Hide WordPress Version
    Hackers scan for outdated WordPress versions. Hide yours by adding to your theme's functions.php:
php
// Remove WordPress version from head
remove_action('wp_head', 'wp_generator');

// Remove version from scripts and styles
function remove_version_from_assets($src) {
    if (strpos($src, 'ver=') !== false) {
        $src = remove_query_arg('ver', $src);
    }
    return $src;
}
add_filter('style_loader_src', 'remove_version_from_assets', 9999);
add_filter('script_loader_src', 'remove_version_from_assets', 9999);

#### 13. Protect wp-admin Directory
    Add an extra password layer on /wp-admin/ at the server level (separate from WordPress login):
    In cPanel → Directory Privacy → select public_html/wp-admin → enable password protection → set a username and password.
    Now anyone visiting /wp-admin/ must enter a password before they even see the WordPress login form. Double protection.

#### 14. Monitor for Malware
- SiteGround: Site Tools → Security → Site Scanner — runs daily scans
- Wordfence: runs scheduled scans and emails you if anything is found
- Sucuri SiteCheck: free online scanner at sitecheck.sucuri.net — scan anytime

#### Quick Priority Checklist
| Priority | Action |
| 🔴 Do immediately | Change admin password, enable 2FA, install Wordfence |
| 🔴 Do immediately | Update WordPress + all plugins + all themes |
| 🔴 Do immediately | Enable SSL/HTTPS |
| 🟡 This week | Add .htaccess security rules |
| 🟡 This week | Harden wp-config.php |
| 🟡 This week | Set up UpdraftPlus backups to cloud |
| 🟢 When ready | Change login URL, disable XML-RPC, hide WP version |
| 🟢 When ready | Add directory password on /wp-admin/ |


Given that you already had two hacked sites today, I'd prioritize the 🔴 red items first — especially enabling 2FA and installing Wordfence on every WordPress site you manage. Most hacks happen because of weak passwords, outdated plugins, or no firewall. Wordfence alone would have blocked most of what happened today.
