Sometimes, websites suddenly appear broken — layouts collapse, styling disappears, and the console shows multiple warnings around “unsafe-inline” or nonce issues. This usually points to a misconfigured Content Security Policy (CSP).
Case Example: Broken Styling After Cache Clear
In one case, a site displayed broken layouts whenever the cache was cleared. The console revealed repeated CSP violations, specifically the error:
its nonce, or ‘unsafe-inline’ appears in neither the style-src directive nor the default-src directive of the Content Security Policy
The Fix
- Check for duplicate CSP headers: Both
.htaccessandfunctions.phpcontained CSP rules. - Remove duplicate headers: Security headers in
.htaccesswere removed. - Review commented-out CSP lines: A previously commented-out CSP directive in the functions file was reactivated.
- Clear cache and test: Once redundant headers were removed, the site styling returned to normal.
It’s suspected that recent changes to Google Analytics scripts may have contributed to the conflict.
Best Practices for CSP in WordPress
- Avoid duplicating security headers across
.htaccessand theme files. - Use nonces or hashes properly if inline scripts or styles are required.
- Test site functionality after implementing security headers.
- Regularly review headers with tools like Google CSP Evaluator.
Why It Matters
A strict CSP improves site security by preventing XSS attacks. However, misconfiguration can cause false positives that break a site’s frontend. This is why security header management should be part of ongoing WordPress Maintenance, ensuring the right balance between security and functionality.
Conclusion
CSP errors like “unsafe-inline” typically arise from overlapping or misconfigured security headers. By removing duplicates and reactivating valid CSP directives, the site returned to normal without compromising security.




