Skip to content

Instantly share code, notes, and snippets.

@joshuadavidnelson
Last active January 12, 2018 06:23
Show Gist options
  • Save joshuadavidnelson/d5ded4c68e2d562a97d0 to your computer and use it in GitHub Desktop.
Save joshuadavidnelson/d5ded4c68e2d562a97d0 to your computer and use it in GitHub Desktop.
Force SSL on all pages
<?php
/**
* Force SSL on all pages
*
* @author Joshua David Nelson, joshuadnelson.com
**/
add_action( 'template_redirect', 'jdn_force_ssl' );
function jdn_force_ssl() {
// force all pages to https://
if ( is_ssl() )
return;
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