When a browser loads a page from your site, it receives more than HTML. Every response comes with headers, small instructions that tell the browser how to treat the content. Some of those headers exist purely for security. They tell the browser not to let your pages be framed by other sites, not to guess file types, not to leak full URLs to other domains and not to give scripts access to the camera or microphone unless you’ve decided they need it. Getting WordPress security headers right takes perhaps half an hour, and it closes off several types of attack that no plugin update will ever fix for you.
We’ve covered Content Security Policy and HSTS separately, because each of those deserves a full article. This one covers the rest: the smaller, simpler headers that every WordPress site should send, what each one does, sensible values and how to add them without breaking anything.
How to check what you’re sending now
Before changing anything, see what your site sends today. The quickest way is the command line:
| <code>curl -sI https://example.com/ | grep -iE "x-frame | x-content | referrer | permissions | cross-origin | strict-transport | content-security"</code> |
|---|
You can also open your browser’s developer tools, go to the Network tab, click the main document request and look at the Response Headers section. Online scanners such as securityheaders.com give you a graded report and explain what’s missing.
Many WordPress sites send none of these headers at all. Some send them twice, because a plugin, the theme, the web server and a CDN each add their own. Duplicates with conflicting values cause unpredictable behaviour, so part of the job is deciding which layer is responsible.
X-Content-Type-Options
This header has a single sensible value:
Browsers sometimes try to guess what a file really is, regardless of what the server says. That behaviour, called MIME sniffing, can be abused. If an attacker manages to upload a file that’s served as plain text or an image but actually contains script, a sniffing browser might execute it. With nosniff, the browser trusts the declared content type and refuses to run scripts or styles served with the wrong type.
It’s safe on virtually every WordPress site. The only time it causes trouble is when a server sends incorrect content types for CSS or JavaScript, which is a bug worth fixing anyway.
Frame protection: X-Frame-Options and frame-ancestors
Clickjacking is an attack where your site is loaded invisibly inside a frame on another site. The attacker overlays their own content and tricks visitors into clicking buttons on your page without realising it, for example approving an action while logged in.
The traditional defence is:
That allows your own site to frame its pages, which WordPress needs for things like the Customizer preview, while blocking every other site.
The modern equivalent is the frame-ancestors directive in Content Security Policy:
If you already send a CSP, add frame-ancestors to it. Sending both X-Frame-Options and frame-ancestors is fine and covers older browsers. WordPress itself sends X-Frame-Options: SAMEORIGIN on the login page and admin screens, but not on the front end, so you need to add it for public pages.
If you deliberately allow embedding by specific partners, list them in frame-ancestors. X-Frame-Options can’t express that.
Referrer-Policy
When a visitor clicks a link from your site to another site, the browser tells the destination where they came from through the Referer header. By default, modern browsers send only the origin, such as https://example.com/, to other sites. But older defaults and some configurations send the full URL, including paths and query strings.
Full URLs can leak more than you’d like. Password reset links, search terms, order confirmation pages with order IDs in the URL and internal admin paths can all end up in another site’s analytics.
A good default is:
That sends the full URL for links within your own site, which keeps your analytics working, sends only the origin to other sites and sends nothing when going from HTTPS to HTTP. It’s the browser default today in most cases, but declaring it explicitly makes the behaviour consistent everywhere.
For sites handling sensitive information, such as healthcare portals, you might choose same-origin or no-referrer instead, at the cost of less referral data for sites you link to.
Permissions-Policy
Modern browsers give web pages access to powerful features: camera, microphone, geolocation, payment APIs, USB devices and more. Permissions-Policy lets you declare which features your pages are allowed to use, and which embedded third-party frames may request them.
For a typical business site that uses none of these features:
The empty parentheses mean the feature is disabled for your page and for every frame inside it. If a compromised plugin or a malicious ad script tries to request the microphone, the browser refuses without even asking the visitor.
Be careful to allow what you actually use. If your store uses the Payment Request API for Apple Pay or Google Pay buttons, set payment=(self) and include the payment provider’s origin if their frames need it. If you have a store locator that uses the visitor’s location, allow geolocation=(self). Test those features after adding the header.
Cross-Origin-Opener-Policy
This header controls whether pages opened from your site, or pages that open yours, can interact with your window. It protects against a class of cross-window attacks and is part of the isolation browsers need for certain advanced features.
The same-origin-allow-popups value is a practical choice for WordPress, because it still allows popups you open, such as payment provider windows or social login flows, to communicate back to your page. Stricter values like same-origin can break OAuth logins and some payment flows, so test carefully if you use them.
Headers you can skip
Some headers show up in older guides but are no longer useful:
- X-XSS-Protection controlled a filter that modern browsers have removed. Setting it to 0, or not sending it at all, is the current advice.
- Expect-CT was for certificate transparency enforcement and is obsolete.
- Public-Key-Pins was dangerous and has been removed from browsers.
If a plugin or scanner tells you to add these, it’s working from outdated advice.
Where to add the headers
You can set security headers in several places. Choose one and stick with it.
In Nginx
Add the headers to your server block:
The always parameter ensures headers are sent on error pages too. Be aware of an Nginx quirk: add_header directives are inherited by location blocks only if those blocks don’t contain any add_header directives of their own. If a location block adds its own header, for example for caching static files, it loses all the security headers from the server level. Many people discover this months later. The cleanest fix is to put the security headers in a separate file and include it in every location block that adds headers.
In Apache
In .htaccess or the virtual host:
At the CDN
Cloudflare and other CDNs can add response headers with transform rules. This is convenient if you don’t control the server, and it applies headers to cached responses consistently.
In WordPress
Plugins and code using the send_headers or wp_headers hooks can add headers. This works on any host but only applies to responses generated by WordPress, not to static files served directly by the web server, and it doesn’t apply when pages come from a full-page cache that bypasses PHP. Server or CDN configuration is more reliable.
Testing after changes
After adding headers, check:
- The headers appear on the homepage, a post, a product page and a 404 page.
- They appear on cached pages as well as uncached ones.
- There’s only one copy of each header.
- The Customizer and Site Editor previews still work.
- Embedded content you rely on, such as videos and maps, still loads.
- Payment buttons, social logins and any camera or location features still work.
Run a scanner again and compare the grade with your starting point. The goal isn’t a perfect score for its own sake. It’s a deliberate, documented set of WordPress security headers that you understand and that doesn’t break your site.
A sensible baseline for most sites
If you just want a starting point, this combination suits the majority of WordPress business sites: nosniff, SAMEORIGIN frame protection with a matching frame-ancestors directive, strict-origin-when-cross-origin for referrers, a Permissions-Policy that disables camera, microphone, geolocation and USB, and same-origin-allow-popups for the opener policy. Add HSTS once you’re confident HTTPS works everywhere, and work towards a Content Security Policy over time.
Write the chosen values into your server documentation with a short note explaining each one. When someone later asks why a partner can’t embed your booking page, or why a new map widget can’t access location, the note answers the question in seconds instead of starting an investigation.
Frequently asked questions
Will security headers affect SEO?
No. Search engines ignore these headers for ranking purposes. They only affect how browsers treat your pages.
Do I need these if I have a security plugin?
Security plugins protect WordPress itself. Headers protect visitors’ browsers. They complement each other. Some security plugins can add headers for you, which is fine as long as nothing else adds duplicates.
Can security headers break my site?
X-Content-Type-Options and Referrer-Policy rarely cause problems. Frame protection can break legitimate embedding by partners, and Permissions-Policy can break features you forgot you use. Test after changes.
Should headers be different on staging?
The same headers are fine on staging. Staging should also block indexing and use password protection, which are separate measures.




