Last active
December 15, 2015 14:59
-
-
Save martynchamberlin/5278521 to your computer and use it in GitHub Desktop.
Force SSL on WordPress Pages, in this case, a page with an ID of 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$using_ssl = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' || $_SERVER['SERVER_PORT'] == 443; | |
add_action('wp', 'check_ssl'); | |
function check_ssl() | |
{ | |
// Page ID 2 must be https | |
if (is_page(2) && !$using_ssl) | |
{ | |
header('HTTP/1.1 301 Moved Permanently'); | |
header('Location: https://' . $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']); | |
exit; | |
} | |
// All other pages must not be https | |
else if (!is_page(2) && $using_ssl) | |
{ | |
header('Location: http://' . $_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
You may want to add a variable for the page ID: https://gist.github.com/seangates/23290bd3946cbe5c2a0e
Otherwise you may forget to change it in every place it's needed.