0

The following function works perfectly when logged-in visitors go to http://sitename.com, taking them to the site homepage. When logged-in visitors go to http://www.sitename.com, however, they're incorrectly redirected to http://sitename.com/splashpage. Does anyone know what's causing this?

I have tried switching my site settings to use http://www.sitename.com as the WordPress and Site Address URLs, but that simply reverses the issue so it incorrectly redirects when a logged-in user goes to http://sitename.com.

// REDIRECT USERS TO SPLASH PAGE IF THEY'RE NOT LOGGED IN
add_action ('template_redirect','mkm_restrict_access',1);
function mkm_restrict_access() {
    $url = site_url('/splashpage/');
    if (is_page('splashpage') || is_page('login')) {
        //do nothing
    } elseif (!is_user_logged_in()) {
        wp_redirect( $url ); 
        exit; 
    }
}

Thank you for your help!

1
  • Is there perhaps a better action to use to call this redirect? Something that fires after the page redirects from example.com to example.com ? – Michelle Aug 4 '11 at 19:39
0

Figured it out, though this is the lamest solution ever: I hooked into wp_footer instead of template_redirect. If anyone has a better solution or place to hook in I'd love to hear about it - thanks!

EDIT: That wasn't the fix I thought it was. Turned out I was writing the function poorly, and did need to be using template_redirect. See Cannot get redirect working

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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