Skip to main content
5 of 8
added 8 characters in body
sakibmoon
  • 2.3k
  • 1
  • 19
  • 25

The is_login_page() function is taken from here

function is_login_page() {
    return in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'));
}

function my_redirect() {  
    //if you have the page id of landing. I would tell you to use if( is_page('page id here') instead
    //Don't redirect if user is logged in or user is trying to sign up or sign in
    if( !is_login_page() && !is_admin() && !is_user_logged_in()){
        //$page_id is the page id of landing page
        if( !is_page($page_id) ){
            wp_redirect( get_permalink($page_id) );
            exit;
        }
    }
}
add_action( 'init', 'my_redirect' );
sakibmoon
  • 2.3k
  • 1
  • 19
  • 25