WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using this code in functions.php to load https on my events-manager pages:

function my_em_force_ssl( $template ) {
    if ( ! is_ssl() && em_is_event_page() ) {
        wp_redirect( str_replace( 'http:', 'https:', get_permalink() ) );

    return $template;

add_filter( 'template_redirect', 'my_em_force_ssl', 10 );

Is there a way to unload or revert back to http when leaving those pages?

share|improve this question

Not tested, but give it a shot:

function my_em_force_ssl() {
    if ( ! is_ssl() && em_is_event_page() ) {
        wp_redirect( str_replace( 'http:', 'https:', get_permalink() ) );
    } elseif ( is_ssl() && ! em_is_event_page() && $_SERVER['REQUEST_METHOD'] === 'GET' ) {
            str_replace( 'https:', 'http:',
                    $_GET, site_url( $GLOBALS['wp']->request )

add_action( 'template_redirect', 'my_em_force_ssl', 10 );

And a heads up, template_redirect is an action, so no need to accept & pass back params :)

share|improve this answer
Thanks man, that worked like a charm :) Now I just need to figure out a way to load the images https and other site elements.. awesome! – neptune_surf Jun 24 '13 at 20:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.