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!