Securing your WordPress site goes far beyond just choosing a strong password or installing a trusted security plugin. One critical layer of defense that is often overlooked is the addition of HTTP Security Headers. These headers bolster your website’s resistance to various types of attacks, including cross-site scripting (XSS), clickjacking, and MIME-sniffing. In this step-by-step tutorial, you’ll learn how to add these essential headers to your WordPress site, improving both its security and privacy.
What Are HTTP Security Headers?
HTTP Security Headers are directives given by the web server to the browser, instructing it on how to behave when handling your website content. These headers act as a barrier, helping to mitigate security vulnerabilities. Below are the most widely used and impactful headers:
- Content-Security-Policy (CSP): Prevents XSS and data injection attacks.
- X-Frame-Options: Protects against clickjacking attacks.
- X-Content-Type-Options: Prevents MIME-type sniffing.
- Strict-Transport-Security (HSTS): Enforces HTTPS connections.
- Referrer-Policy: Controls what information is sent in the HTTP Referer header.
- Permissions-Policy: Governs access to browser features like camera, microphone, and geolocation.
If you’re unsure whether your site already uses these headers, you can inspect it easily using browser developer tools or online services like SecurityHeaders.com.

Step 1: Back Up Your WordPress Site
Before making any changes, it’s essential to back up your entire WordPress site — files and database included. This way, if something goes wrong, you can revert to a stable version without losing data.
Use trusted plugins like UpdraftPlus, All-in-One WP Migration, or take manual backups via cPanel or FTP and phpMyAdmin.
Step 2: Choose How You’ll Add Headers
There are three primary ways to add HTTP security headers to your WordPress website:
- Modify .htaccess (for Apache servers)
- Edit nginx.conf (for NGINX servers)
- Install a plugin that supports security headers
The easiest route for non-developers is to use a WordPress security plugin, but developers or those comfortable with server configuration may prefer modifying configuration files directly.
Step 3: Modifying .htaccess (Apache)
If your server uses Apache, follow these steps:
- Access your site via FTP or File Manager in your hosting control panel.
- Locate your root directory and find the
.htaccess
file. - Backup the file before modifying it.
- Add the following snippet to the top of your
.htaccess
file:
# Security Headers
Header set Content-Security-Policy "default-src 'self';"
Header always set X-Content-Type-Options "nosniff"
Header always set X-Frame-Options "SAMEORIGIN"
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
Header always set Permissions-Policy "geolocation=(), microphone=(), camera=()"
Note: Modify the Content-Security-Policy to match the resources your site uses to avoid breaking functionalities.
Step 4: Modifying NGINX.conf (NGINX Servers)
For NGINX users, headers are added inside your server block. Locate and edit your NGINX configuration file:
add_header Content-Security-Policy "default-src 'self';";
add_header X-Content-Type-Options "nosniff";
add_header X-Frame-Options "SAMEORIGIN";
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
add_header Referrer-Policy "strict-origin-when-cross-origin";
add_header Permissions-Policy "geolocation=(), microphone=(), camera=()";
After editing, test your configuration using:
sudo nginx -t
And then reload NGINX:
sudo systemctl reload nginx
Step 5: Using Security Plugins (Beginner-Friendly)
If server access isn’t your thing, security plugins offer a smoother path. Consider these options:
- HTTP Headers Plugin: Simple, dedicated plugin for adding headers.
- Security Ninja Pro: Includes a full suite of options, including security headers.
- Redirection: Apart from managing redirects, it can also add custom HTTP headers.
Once the plugin is installed and activated:
- Navigate to the plugin’s setting page.
- Add the necessary header values as described above.
- Save settings and test the site.
Step 6: Test Your Security Headers
After implementing the changes, verify them to ensure they’re working correctly. Use these tools:
- SecurityHeaders.com
- Mozilla Observatory
- Browser Developer Tools > Network Tab > Inspect Response Headers
These tools will give you real-time feedback and even a score reflecting your site’s security posture. Aim for an A+ security rating!
Tips and Best Practices
- Test changes in staging: Always apply these changes on a staging server before going live.
- Tailor your policies: Don’t rely on copy-paste headers. Custom-tailor CSP to match specific domains used for scripts, fonts, etc.
- Keep server software up to date: Headers are only one piece of the security puzzle.
- Use HTTPS: Many security headers like HSTS require a valid SSL certificate in place.
Conclusion: Small Changes, Big Impact
Adding HTTP security headers may initially seem like a complicated task, but once broken down step-by-step, it’s a straightforward and rewarding security upgrade for your WordPress site. Whether you’re a seasoned developer or a casual site owner, implementing these headers helps you take control of your site’s safety and protect your visitors from common threats.
Security is never a one-time fix — consider regular audits, plugin reviews, and server checks to maintain a robust online presence. Every layer counts, and HTTP headers are one of the simplest yet most powerful shields you can deploy.
Stay informed. Stay secure.