WordPress powers a significant portion of the web, making it a constant target for attackers. As a developer, your role is crucial in building and maintaining sites that are resilient to these threats. Robust security isn’t a feature; it’s a fundamental responsibility.
Here’s a comprehensive checklist of best practices to secure your WordPress sites, focusing on the developer’s perspective.
1. Core Maintenance & Hosting Security
The foundation of a secure site lies in its environment and core components.
Keep Everything Up-to-Date
This is the single most effective security measure.
- WordPress Core: Implement a strategy to apply updates immediately, either via auto-updates or scheduled maintenance. Updates frequently include patches for critical vulnerabilities.
- Themes and Plugins: Regularly audit and update all themes and plugins. Delete any unused or deactivated ones, as they are still files on the server and can be exploited.
- Server Software: Ensure your hosting environment runs the latest stable versions of PHP, MySQL/MariaDB, and OpenSSL. Outdated server software can introduce vulnerabilities outside of WordPress itself.
Your host provides the first line of defense.
- Opt for a reputable, managed WordPress host that offers server-level security features like Web Application Firewalls (WAF), DDoS protection, and isolation between accounts on shared hosting.
- Enforce SSL/HTTPS across the entire site by installing an SSL certificate. This encrypts all data transmitted between the user’s browser and your server.
2. Access Control and Authentication
Weak credentials and permissions are primary targets for brute-force and privilege escalation attacks.
Strengthen Login Credentials
Brute-force attacks are a major threat.
- Avoid “admin”: Never use the default username admin. When setting up a site, choose a unique, non-obvious administrator username.
- Strong Passwords: Enforce complex, unique passwords for all users (Admin, FTP, Database, and Hosting control panel). Ideally, use a password manager to generate and store them.
- Two-Factor Authentication (2FA): Implement 2FA for all administrator and high-privilege user accounts using a reputable plugin. This adds a critical layer of defense.
Principle of Least Privilege
Limit what users and code can do.
- User Roles: Only assign the Administrator role to the necessary, trusted users. Use the principle of Least Privilege, assigning users (Editors, Authors, etc.) only the capabilities they need to perform their jobs.
- Disable File Editing: Prevent administrators from editing plugin and theme files directly via the WordPress dashboard by adding define( 'DISALLOW_FILE_EDIT', true ); to your wp-config.php file.
3. Server-Level & Hardening Configuration
These technical measures block common exploits and reduce the attack surface.
Secure Key Files and Directories
Use your server’s configuration files (.htaccess for Apache, or equivalent for Nginx) to enforce restrictions.
- Restrict Access to wp-config.php: Set file permissions to the most restrictive level possible, typically 644 for files and 755 for directories. The wp-config.php file, which contains your database credentials, should ideally be set to 400 or 440.
- Disable Directory Browsing: Prevent hackers from seeing the contents of your directories (like /wp-content/uploads/) by adding Options -Indexes to your .htaccess file.
- Disable PHP Execution in Uploads: Prevent malicious PHP files from being executed in the /wp-content/uploads/ directory by placing an .htaccess file inside it with directives to deny execution.
Non-default settings make targeted attacks harder.
- Change Database Prefix: During installation, or with a security plugin, change the default database table prefix (wp_) to a unique, random string (e.g., wp_a7b4z_).
- Update Security Keys/Salts: Ensure your unique authentication keys and salts in wp-config.php are long, random, and not the defaults. You should also regenerate them immediately after a breach.
Disable XML-RPC (If Unused)
The xmlrpc.php file is a common vector for brute-force and DDoS attacks.
- If you don’t use the WordPress mobile app, Jetpack, or other services that rely on this protocol, disable it entirely via a plugin or server configuration.
How to Secure Your WordPress Site: Best Practices for Developers
Protect your WordPress site with strong passwords, regular updates, security plugins, and SSL encryption. These measures help prevent hacks and ensure data safety.