Skip to content

Instantly share code, notes, and snippets.

@martynchamberlin
Created April 23, 2014 22:22
Show Gist options
  • Save martynchamberlin/11234552 to your computer and use it in GitHub Desktop.
Save martynchamberlin/11234552 to your computer and use it in GitHub Desktop.
In case you need to force HTTPS on every single page of a WordPress site, here's how.
<?php
$using_ssl = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' || $_SERVER['SERVER_PORT'] == 443;
add_action('wp', 'check_ssl');
function check_ssl()
{
// All pages must be https. Redirect to https if not already
if (! $using_ssl)
{
header('HTTP/1.1 301 Moved Permanently');
header('Location: https://' . $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']);
exit;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment