19/08/2017
By Imran M
By Imran M
So, you’ve just launched your shiny new WordPress website. The theme is perfect, the copy is polished, and you’re ready to welcome the world. It’s an exciting time. But here’s the uncomfortable truth: the internet is also ready for you. Automated bots are constantly scanning for new, vulnerable sites to exploit, sometimes even for fun. A new site isn’t a small target; it’s a low-hanging one. Thinking “I’ll implement wordpress security later” is like building a house and deciding to add the doors after you move in. Proactive protection isn’t an extra feature ; it’s a foundation.
Some of the most robust defenses are applied at the server level. This is where your .htaccess
file comes in. By adding a few lines of code, you can instruct the browser to interact with your site in a much more secure way.
Heads-up: Always back up your .htaccess
file before editing it. A single typo can break your site.
Here’s a powerful set of security headers you should implement. You can add this block directly to your .htaccess
file (usually found in your root WordPress directory).
# BEGIN SECURITY HEADERS # Enable XSS Protection Header set X-XSS-Protection "1; mode=block" # Prevent MIME-type sniffing Header set X-Content-Type-Options "nosniff" # Referrer Policy (Improves privacy) Header set Referrer-Policy "no-referrer-when-downgrade" # Combined Content Security Policy (CSP) for XSS Prevention Header set Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' * data:; font-src 'self' data:; connect-src 'self'; frame-ancestors 'self';" # Prevent Clickjacking (X-Frame-Options) Header always set X-Frame-Options "SAMEORIGIN" # Strict Transport Security (HSTS) - Only if SSL is active Header set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" # END SECURITY HEADERS
X-XSS-Protection: Stops pages from loading if they detect a reflected cross-site scripting (XSS) attack. It’s a first line of defense.
X-Content-Type-Options: Tells browsers to respect the file types you set and not to “sniff” them, preventing them from treating a text file as executable code.
Referrer Policy: Controls how much information is sent through the Referer
header when a user clicks a link, protecting user privacy.
Content-Security-Policy (CSP): This is a powerful directive to prevent XSS attacks. It whitelists trusted sources for scripts, styles, and images. Note: The one above is a common starter policy, but you may need to adjust it if you use external services like Google Fonts or YouTube embeds.
X-Frame-Options: Protects your site from “clickjacking” attacks where your site is loaded in an invisible frame to trick users into clicking something else.
Strict-Transport-Security (HSTS): Forces the browser to only use HTTPS to communicate with your site, making it impossible to bypass your SSL certificate. Only enable this after you’ve confirmed your SSL is working 100%.
Headers are a fantastic start, but true WordPress security is layered. Here are the other mandatory implementations for a new site.
Strong Credentials: Avoid admin
as a username. Use a long, unique, and complex password. Use a password manager to generate and store them. This is your front door—don’t leave the key under the mat.
Keep Everything Updated: WordPress core, themes, and plugins. Updates often contain critical security patches. Enable auto-updates for minor core releases and for plugins you trust.
The default /wp-admin
login page is a giant target. Brute force attacks try thousands of username/password combinations. You must protect it.
Limit Login Attempts: Use a plugin like Wordfence or Limit Login Attempts Reloaded to block IP addresses after 3-5 failed attempts.
Change the Login URL: Plugins like WPS Hide Login let you change /wp-admin
to something unique, like /my-secret-entry
(don’t use that one). This stops a huge portion of automated attacks before they even start.
Not every user needs administrator access. Be ruthless with user roles.
Author? Can publish and edit their own posts.
Editor? Can publish and manage posts, including others’.
Administrator? Full, unrestricted access. Hand this out only to people who absolutely need it.
Security isn’t just about prevention; it’s about recovery. If the worst happens, a backup is your only way out.
3: Keep at least three copies of your data.
2: Store them on two different types of media (e.g., your server and cloud storage).
1: Keep one backup copy offsite entirely.
Plugins like UpdraftPlus or BlogVault make this simple and automated. Test your backups periodically to ensure they work.
While the headers above are manual, a good security plugin provides a firewall and real-time monitoring.
Wordfence or Sucuri are industry standards. They offer a Web Application Firewall (WAF) that filters malicious traffic before it even reaches your site.
Implement security headers in .htaccess
Install an SSL certificate and force HTTPS
Change the default admin username
Install a security plugin (Wordfence/Sucuri)
Limit login attempts and/or change the login URL
Set up automated, offsite backups
Delete any unused themes and plugins
Review and assign user roles carefully
Building a secure WordPress site from day one isn’t paranoia; it’s responsibility. An hour of setup now can save you from the nightmare of a hacked site, lost data, and broken trust later.
Now go launch with confidence. if you face any issues, send me a note and I ll help you.