Skip to content

Instantly share code, notes, and snippets.

@defulmere
Created January 21, 2022 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save defulmere/2c80a727f95400852859125955fbcf9d to your computer and use it in GitHub Desktop.
Save defulmere/2c80a727f95400852859125955fbcf9d to your computer and use it in GitHub Desktop.
Simple plugin to enable security headers in Wordpress, drop into the plugins directory and then enable via your WP dashboard
<?php
/*
Plugin Name: Add Security Headers
Description: adds security headers to wordpress
*/
function add_security_headers() {
if ( $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on' ) {
header('Strict-Transport-Security: max-age=31536000');
header('X-XSS-Protection: 1; mode=block');
header('X-Content-Type-Options: nosniff');
header('X-Frame-Options: DENY');
}
}
add_action( 'send_headers', 'add_security_headers' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment