Skip to content

Instantly share code, notes, and snippets.

@themightymo
Created October 21, 2024 21:52
Show Gist options
  • Save themightymo/685840991c9efae371a5ecbbf9a4aa80 to your computer and use it in GitHub Desktop.
Save themightymo/685840991c9efae371a5ecbbf9a4aa80 to your computer and use it in GitHub Desktop.
Enable HSTS via WordPress functions.php
/**
* Enables the HTTP Strict Transport Security (HSTS) header in WordPress.
* Includes preloading with subdomain support.
* via https://thomasgriffin.com/enable-http-strict-transport-security-hsts-wordpress/
*/
function tg_enable_strict_transport_security_hsts_header_wordpress() {
header( 'Strict-Transport-Security: max-age=31536000; includeSubDomains; preload' );
}
add_action( 'send_headers', 'tg_enable_strict_transport_security_hsts_header_wordpress' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment