Best Security Header Settings for WordPress Plugins and Themes

Implementing the right security headers is essential for protecting your WordPress website from common threats such as clickjacking, cross-site scripting (XSS), and other malicious attacks. Proper security headers help browsers understand how to handle your site’s content securely and can prevent unauthorized access or data leaks.

Why Security Headers Matter

Security headers act as a first line of defense by instructing browsers on how to process your website’s content. They can restrict framing, control content sources, enforce HTTPS, and prevent the execution of untrusted scripts. Proper configuration of these headers enhances your site’s security and builds trust with your visitors.

Key Security Headers for WordPress

  • Content-Security-Policy (CSP): Defines which sources are trusted for scripts, styles, images, and other resources.
  • X-Frame-Options: Prevents your site from being embedded in iframes, protecting against clickjacking.
  • X-Content-Type-Options: Stops browsers from MIME-sniffing a response away from the declared content-type.
  • Strict-Transport-Security (HSTS): Enforces secure (HTTPS) connections.
  • Referrer-Policy: Controls how much referrer information is included with requests.

To maximize security, configure your server or use security plugins that allow you to set these headers. Here are recommended configurations:

Content-Security-Policy

Limit sources to trusted domains. Example:

Content-Security-Policy: default-src 'self'; script-src 'self' https://trustedscript.com; style-src 'self' https://trustedstyle.com; img-src 'self' data:;

X-Frame-Options

Set to deny or sameorigin to prevent framing:

X-Frame-Options: DENY

X-Content-Type-Options

Enforce MIME type checking:

X-Content-Type-Options: nosniff

Strict-Transport-Security

Force HTTPS connections for secure browsing:

Strict-Transport-Security: max-age=31536000; includeSubDomains; preload

Referrer-Policy

Control referrer information:

Referrer-Policy: no-referrer-when-downgrade

Implementing Security Headers

You can add these headers through your server configuration (like Apache or Nginx), or use WordPress security plugins such as Wordfence or Sucuri Security. These plugins often provide options to add custom headers easily without editing server files.

Conclusion

Proper security header configuration is a vital step in safeguarding your WordPress site. Regularly review and update these settings, especially after plugin or theme updates, to ensure your site remains protected against evolving threats.