Security 5 min read

HTTP security headers for WordPress sites

HTTP security headers for WordPress explained: HSTS, Content-Security-Policy, X-Frame-Options, X-Content-Type-Options, Referrer-Policy, Permissions-Policy and how to add them.

Usman Muhammad UsmanUpdated October 13, 2026
HTTP security headers for WordPress sites

HTTP security headers are instructions your server sends with each page, telling browsers how to handle your content. They help prevent attacks such as clickjacking, content injection and protocol downgrades. Adding them is usually quick, though a few need careful testing. Here are the headers I set on client sites and how to add them safely.

What security headers do

When a browser loads a page, it receives response headers along with the content. Security headers enable browser protections: forcing HTTPS, controlling which sites can embed your pages, preventing browsers from guessing file types and limiting which scripts and features can run.

They do not fix vulnerabilities in your site, but they reduce the impact of some attacks and close common gaps. Security scanners and audits often check for them.

Strict-Transport-Security (HSTS)

HSTS tells browsers to always use HTTPS for your domain for a set period, even if someone types http or follows an old link. It prevents downgrade attacks and removes a redirect for returning visitors.

Enable it only once HTTPS works everywhere on your site and subdomains, starting with a short max-age and increasing it later. Adding includeSubDomains and preload is a long-term commitment. See setting up SSL and HTTPS.

Key security headers
HeaderProtects againstDifficulty
HSTSHTTPS downgradeEasy, test first
X-Frame-OptionsClickjackingEasy
X-Content-Type-OptionsMIME sniffingEasy
Referrer-PolicyURL leakageEasy
Permissions-PolicyFeature misuseModerate
Content-Security-PolicyScript injectionAdvanced

X-Frame-Options and frame-ancestors

These headers control whether other websites can display your pages inside a frame. Blocking framing prevents clickjacking, where attackers trick users into clicking hidden elements on your site. X-Frame-Options set to SAMEORIGIN allows only your own site to frame pages.

The modern equivalent is the frame-ancestors directive in Content-Security-Policy. Use either or both.

X-Content-Type-Options

Setting X-Content-Type-Options to nosniff tells browsers not to guess the type of files and to trust the declared content type. This prevents some attacks where uploaded files are interpreted as scripts.

It is safe for almost all sites and has no visible effect on normal browsing.

Referrer-Policy

Referrer-Policy controls how much information about the previous page is sent when visitors follow links. A setting such as strict-origin-when-cross-origin sends the full address within your site but only your domain to other sites, protecting private URLs and query strings.

This is the default in modern browsers, but setting it explicitly ensures consistent behaviour.

Permissions-Policy

Permissions-Policy controls which browser features, such as camera, microphone, geolocation and payment, your pages and embedded content can use. Disabling features you do not need reduces the risk of misuse by injected or third-party scripts.

Make sure you do not disable features your site uses, such as geolocation for store locators or payment request features for checkout.

Content-Security-Policy

Content-Security-Policy (CSP) is the most powerful and complex header. It defines which sources of scripts, styles, images, fonts and frames are allowed. A strict CSP can block injected scripts, including card skimmers on checkout pages.

WordPress sites load resources from many sources, so CSP needs careful setup. Start in report-only mode to see what would be blocked, then tighten gradually. Test every page type and plugin.

Adding headers on Apache and Nginx

On Apache servers, headers can be added in .htaccess with Header set directives, if mod_headers is enabled. On Nginx, they are added in the server configuration with add_header. Your host may provide an interface or add them on request.

Back up configuration files before editing. A syntax error can take the site offline. See cPanel basics.

Adding headers with Cloudflare or plugins

Cloudflare can add response headers with Transform Rules, and its SSL settings include HSTS. Security plugins and dedicated header plugins can also add headers from the WordPress dashboard, which is convenient but only applies to pages WordPress serves.

Server or CDN-level headers cover all files, including images and static assets. See setting up Cloudflare.

Testing headers

Use online tools such as securityheaders.com or Mozilla Observatory to check which headers your site sends and get recommendations. Browser DevTools show response headers in the Network tab for each request.

After adding headers, test key pages, forms, embeds, payment pages and the admin area to make sure nothing breaks.

Headers to avoid or update

X-XSS-Protection is deprecated in modern browsers and can be omitted or set to 0. Feature-Policy has been replaced by Permissions-Policy. Expect-CT is no longer needed. Remove outdated headers to keep configuration clean.

Check for duplicate headers set by both the server and a plugin, which can cause unexpected behaviour.

Headers on WooCommerce checkout pages

Checkout and account pages handle the most sensitive data, so they benefit most from strict headers. A Content-Security-Policy that allows scripts only from your own domain and your payment provider can block injected skimmers. Payment providers publish the domains their scripts and frames need.

Build the policy in report-only mode on checkout first, review reports for legitimate sources such as analytics and fraud tools, then enforce it. Re-test after adding payment methods or checkout extensions, since each can introduce new script sources.

Getting help

Security headers are part of my WordPress security audit and hardening checklist. I configure and test them as part of my website protection service.

For checkout protection on stores, read WooCommerce security basics.

Key takeaways

  • Security headers enable browser protections with little effort.
  • Enable HSTS only after HTTPS works across the whole site.
  • Start Content-Security-Policy in report-only mode and test carefully.
  • Set headers at the server or CDN level and test with online tools.

Frequently asked questions

Do security headers affect SEO?

Not directly, though HSTS and HTTPS support a secure experience.

Can security headers break my site?

CSP and Permissions-Policy can if misconfigured. Test before enforcing.

Which headers should every site have?

HSTS, X-Content-Type-Options, X-Frame-Options or frame-ancestors and Referrer-Policy.

Is X-XSS-Protection still needed?

No. It is deprecated in modern browsers.

Can I add headers on shared hosting?

Usually yes, through .htaccess or your host's tools.

Does Shopify let me set security headers?

Shopify manages most headers for you. Custom headers are limited.

How do I check my current headers?

Run your homepage through securityheaders.com or Mozilla Observatory, or open the Network tab in browser DevTools and inspect the response headers.

Free website audit

Get a free audit of your website

Tell me your URL and I'll send a short, prioritized list of the speed, SEO and security fixes that will make the biggest difference.

  • No obligation, no sales call
  • 5.0 rating on Google and Upwork
  • Reply within one business day
Written by Muhammad UsmanWeb Development Team Lead with 5+ years building WordPress, WooCommerce, Shopify and Wix websites. Experience · Certificates About me

More on Security

All Security articles

Have a project in mind?

Tell me what you're building and I'll reply with next steps and an estimate.