Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question
    
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
add comment

1 Answer

up vote 0 down vote accepted

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

share|improve this answer
add comment

Your Answer

 
discard

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.