Create a gist now

Instantly share code, notes, and snippets.

Embed
/**
* Redirect WordPress front end https URLs to http without a plugin
*
* Necessary when running forced SSL in admin and you don't want links to the front end to remain https.
*
* @link http://blackhillswebworks.com/?p=5088
*/
add_action( 'template_redirect', 'bhww_ssl_template_redirect', 1 );
function bhww_ssl_template_redirect() {
if ( is_ssl() && ! is_admin() ) {
if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) {
wp_redirect( preg_replace( '|^https://|', 'http://', $_SERVER['REQUEST_URI'] ), 301 );
exit();
} else {
wp_redirect( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 301 );
exit();
}
}
}
@bhwebworks

This comment has been minimized.

Show comment
Hide comment
@bhwebworks

bhwebworks Apr 3, 2015

If you need one or more front-end pages or posts to be https, check out this Gist: https://gist.github.com/bhwebworks/3cf728c5d5e0c021105f

Owner

bhwebworks commented Apr 3, 2015

If you need one or more front-end pages or posts to be https, check out this Gist: https://gist.github.com/bhwebworks/3cf728c5d5e0c021105f

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost May 3, 2016

Hi,
the code goes in the functions.php file ?
Thank You

ghost commented May 3, 2016

Hi,
the code goes in the functions.php file ?
Thank You

@wpexplorer

This comment has been minimized.

Show comment
Hide comment
@wpexplorer

wpexplorer Jul 18, 2016

Would it be more efficient to hook into 'wp_loaded' instead?

Would it be more efficient to hook into 'wp_loaded' instead?

@bhwebworks

This comment has been minimized.

Show comment
Hide comment
@bhwebworks

bhwebworks Oct 18, 2016

Sorry guys - for some reason I'm not getting notifications from GitHub for these comments.

@noaneo yes, functions.php will work, or in its own plugin, or in a core functionality plugin.

@wpexplorer What are your thoughts on that?

Owner

bhwebworks commented Oct 18, 2016

Sorry guys - for some reason I'm not getting notifications from GitHub for these comments.

@noaneo yes, functions.php will work, or in its own plugin, or in a core functionality plugin.

@wpexplorer What are your thoughts on that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment