Last active
August 29, 2015 14:01
-
-
Save developdaly/74f0af268c04c69a9e92 to your computer and use it in GitHub Desktop.
This snippet will check the current URL's protocol and if it matches http:// then it will redirect to the same URL but replace the protocol with https://
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 | |
add_action( 'after_setup_theme', 'my_plugin_force_ssl' ); | |
/** | |
* Force unencrypted URLs to redirect to an SSL encrypted version. | |
*/ | |
function my_plugin_force_ssl() { | |
$protocol = stripos( $_SERVER['SERVER_PROTOCOL'],'https' ) === true ? 'https://' : 'http://'; | |
if( $protocol == 'http://' ) { | |
$redirect_to = 'https://'. $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]; | |
wp_redirect( esc_url( $redirect_to ), 301 ); | |
exit; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment