Skip to main content
Boost WordPress Security with Essential HTTP Headers

Boost WordPress Security with Essential HTTP Headers

Learn how basic HTTP security headers can protect your WordPress site from common attacks. We'll explore what they do and how to implement one today.

When we talk about WordPress security, people often think about strong passwords, updated plugins, and good backups. All of those are crucial, of course. But there’s another layer of protection that often gets overlooked: HTTP security headers. These aren’t plugins or settings in your WordPress dashboard; they’re instructions your web server sends to a visitor’s browser.

Think of them as a set of rules you give the browser, telling it exactly how to behave when interacting with your site. These rules can prevent several common attack types, even if your WordPress site itself has a small vulnerability. They’re a bit like a sturdy fence around your property, keeping out mischief before it even gets to your front door.

What Exactly Are Security Headers?

Security headers are lines of code added to your web server’s configuration. When a browser requests a page from your WordPress site, your server sends back the page’s content along with these headers. The browser then reads these instructions and applies them. They act as a proactive defense, guiding the browser to make safer choices.

I’ve seen many sites, even well-maintained ones, leave these headers unset. It’s a missed opportunity for easy, effective security. For 17 years, working with clients from New Zealand to Germany, I’ve consistently found that small, technical improvements make a big difference.

Common Security Headers and What They Do

Let’s look at a few common security headers in plain language:

  • Strict-Transport-Security (HSTS): This header tells a browser, “Only ever connect to this site using HTTPS.” If a visitor tries to access your site using plain HTTP (which isn’t encrypted), HSTS forces their browser to switch to the secure HTTPS connection instead. This prevents ‘man-in-the-middle’ attacks where someone might try to intercept unencrypted traffic.
  • X-Content-Type-Options: This one is simple but effective. It tells the browser, “Don’t try to guess the file type of content I’m sending; just trust what I tell you it is.” This stops a tricky attack called ‘MIME sniffing,’ where an attacker might try to trick a browser into executing a malicious file by disguising it as something innocent.
  • X-Frame-Options: This header controls whether your site can be embedded within an HTML <iframe> on another website. By setting it correctly, you can prevent ‘clickjacking’ attacks, where an attacker might overlay a malicious, invisible layer over your site to trick users into clicking on something they didn’t intend to.
  • Content-Security-Policy (CSP): This is a powerful, more advanced header. It allows you to specify exactly which sources (domains) your browser can load various types of content from, such as scripts, stylesheets, and images. It’s like a bouncer at a club, only letting in approved guests. Setting this one up properly takes care, but it offers robust protection against cross-site scripting (XSS) attacks.

Set One Security Header Today: HSTS

Of all the security headers, HSTS is one of the easiest to implement for an immediate security boost, especially if your site already uses HTTPS everywhere (which it should!).

Here’s how to add the HSTS header to your WordPress site. You’ll be editing your .htaccess file, which is a core configuration file for Apache servers. Always back up this file before you make changes. If you’re on Nginx, the process is different and you’ll need to edit your Nginx configuration file instead.

Access your site via SFTP or your hosting control panel’s file manager. Look for the .htaccess file in the root directory of your WordPress installation. Open it for editing and add the following lines, usually at the top, after any existing WordPress rules:

<IfModule mod_headers.c>
    Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains" env=HTTPS
</IfModule>

Let’s break down that line:

  • max-age=31536000: This tells the browser to remember this rule for one year (31,536,000 seconds).
  • includeSubDomains: This applies the rule to all subdomains of your site as well (e.g., blog.yourdomain.com).
  • env=HTTPS: This ensures the header is only sent when the connection is already secure.

Save the file, and that’s it! Your site will now tell browsers to always use HTTPS. This small step helps harden your site against certain types of network attacks. When I onboard new clients, whether for an Essential Care Plan or a Custom one, setting up proper security headers is always part of my initial hardening process.

Beyond the Basics

While HSTS is a great start, there’s more to robust WordPress security. My own site, chrisalberto.me, scores 100 on all six cards of my audit and 98–100 on Lighthouse mobile, in part due to careful configuration of these often-invisible settings, alongside other measures like Cloudflare in front of the site.

If you’re unsure about tackling these technical details, that’s what I’m here for. My free website audit checks for these kinds of security gaps, along with speed, SEO basics, and AI search readiness. You’ll get a plain-English report detailing what needs fixing first. It’s a good way to see where your site stands.