WordPress Security ServicesMalware Removal
Scan Findings Explained

Missing Security Headers on WordPress: What They Do and How to Add Them

Security scanners often report a list of "missing security headers": HSTS, X-Frame-Options, X-Content-Type-Options, Content-Security-Policy and more. They're small instructions your server sends to browsers, telling them to be more careful with your site. Here's what each does, which ones matter, and how to add them without breaking anything.

Sergey By Sergey, WordPress security specialist Updated 2 min read
In this guide
  1. The headers and what they do
  2. Safe headers to add (Apache)
  3. Content-Security-Policy: the powerful one
  4. Check your result

The headers and what they do

Header What it does Priority
Strict-Transport-Security (HSTS) Tells browsers to only use HTTPS for your site High, once HTTPS works everywhere
X-Content-Type-Options: nosniff Stops browsers from guessing file types, which can turn an upload into a script High, safe to add
X-Frame-Options / frame-ancestors Stops other sites from embedding yours in a frame (clickjacking) Medium, safe for most sites
Referrer-Policy Limits how much of your URLs is shared with other sites Medium, safe to add
Permissions-Policy Disables browser features you don’t use (camera, microphone…) Low to medium
Content-Security-Policy (CSP) Controls which scripts and resources may load. Strong protection against injected scripts High value, but needs careful setup

Safe headers to add (Apache)

Add to your root .htaccess (requires the mod_headers module, which most hosts have):

<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=()"
</IfModule>

HSTS: add only when your whole site, including subdomains you include, works over HTTPS:

Header always set Strict-Transport-Security "max-age=31536000"

Start with a shorter max-age if you’re unsure. Browsers remember HSTS, so a mistake is hard to undo quickly.

On Nginx, the same headers go into the server configuration with add_header. Ask your host if you can’t edit it.

Content-Security-Policy: the powerful one

A good CSP is one of the best defenses against injected JavaScript, the kind used in redirects, card skimmers and fake CAPTCHAs. But WordPress sites load scripts from many places. The safe way:

  1. Start with Content-Security-Policy-Report-Only so nothing is blocked yet.
  2. Watch the browser console or a reporting service to see what would be blocked.
  3. Build the allowed list, then switch to the real Content-Security-Policy header.

Check your result

After adding headers, test your site with a free header-checking tool and click through it: forms, checkout, embeds and the admin area.

From my cleanup work: on online stores, a well-built Content-Security-Policy is one of the few things that can stop a card skimmer even after it’s been injected, because the browser refuses to send data to the attacker’s domain. It takes some setup, but for shops it’s worth it.

Sergey, WordPress Security Specialist
About the author
Sergey, WordPress Security Specialist

10 years in WordPress security and incident investigation, and more than 200 websites cleaned of malware. Top Rated on Upwork with a 100% Job Success score. More about me

Frequently Asked Questions

Will security headers stop my site from being hacked?

No. Headers protect your visitors' browsers against certain attacks, like clickjacking or content sniffing. They don't fix vulnerable plugins or weak passwords. They're good hygiene, not a firewall.

Why not just add a strict Content-Security-Policy?

Because a strict CSP can easily break a WordPress site that loads scripts from analytics, fonts, embeds or payment providers. Start in report-only mode, see what it would block, and tighten it gradually.

Can I add headers with a plugin?

Yes. Several security and header plugins add them, and Cloudflare can add them too. Adding them at the server level (.htaccess or Nginx) is lighter and works even when WordPress is busy.

Need a hand?

Let me clean your WordPress site for you

Send me your site URL and what you're seeing. I'll reply with what I think is going on and the next step.

$95 per infected site · 1-month guarantee · direct contact with the specialist

Get My Site Cleaned →