Skip to content

Instantly share code, notes, and snippets.

@getneerajk
Created November 15, 2023 03:58
Show Gist options
  • Save getneerajk/26cf3c6b645caec2a26638bac357bb49 to your computer and use it in GitHub Desktop.
Save getneerajk/26cf3c6b645caec2a26638bac357bb49 to your computer and use it in GitHub Desktop.
Set csp headers #wp
<?php
// Add a filter to modify the HTTP headers
function add_csp_header() {
header("Content-Security-Policy: default-src 'self'; script-src 'self' https://example.com; style-src 'self' https://example.com;");
// Add more directives as needed based on your specific requirements
}
// Hook the function to the 'send_headers' action
add_action('send_headers', 'add_csp_header');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment