I've tried this to redirect people who aren't logged in to certain page. It ultimately shouldn't matter what front end page they visit, but should redirect to whatever page is chosen as the landing page (which I'm assuming would be the URL in the wp_redirect). I still need access to wp-login and dashboard etc...
I placed the following code in my functions.php, but did not work.
function my_redirect() {
if ( $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] == 'mybigfatsite.com/' ) {
if ( ! is_user_logged_in() ) {
wp_redirect( 'mybigfatsite.com/landing/' );
exit;
}
}
}
add_action( 'init', 'my_redirect' );
Thanks for any help!
HTTP_HOST
typically doesn't containhttp://
, do some debugging to figure out what you're actually trying to match.