Skip to main content
replaced http://wordpress.stackexchange.com/ with https://wordpress.stackexchange.com/
Source Link

The is_login_page() function is taken from herehere

function is_login_page() {
    if ( $GLOBALS['pagenow'] === 'wp-login.php' && ! empty( $_REQUEST['action'] ) && $_REQUEST['action'] === 'register' )
        return true;
    return false;
}

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( 'template_redirect', 'my_redirect' );

The is_login_page() function is taken from here

function is_login_page() {
    if ( $GLOBALS['pagenow'] === 'wp-login.php' && ! empty( $_REQUEST['action'] ) && $_REQUEST['action'] === 'register' )
        return true;
    return false;
}

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( 'template_redirect', 'my_redirect' );

The is_login_page() function is taken from here

function is_login_page() {
    if ( $GLOBALS['pagenow'] === 'wp-login.php' && ! empty( $_REQUEST['action'] ) && $_REQUEST['action'] === 'register' )
        return true;
    return false;
}

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( 'template_redirect', 'my_redirect' );
updated is_login_page function
Source Link
sakibmoon
  • 2.3k
  • 1
  • 19
  • 25

The is_login_page() function is taken from here

function is_login_page() {
    returnif in_array( $GLOBALS['pagenow'], array(=== 'wp-login.php', 'wp-register.php'&& ! empty( $_REQUEST['action'] ) && $_REQUEST['action'] === 'register' );
        return true;
    return false;
}

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( 'template_redirect', 'my_redirect' );

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( 'template_redirect', 'my_redirect' );

The is_login_page() function is taken from here

function is_login_page() {
    if ( $GLOBALS['pagenow'] === 'wp-login.php' && ! empty( $_REQUEST['action'] ) && $_REQUEST['action'] === 'register' )
        return true;
    return false;
}

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( 'template_redirect', 'my_redirect' );
added 13 characters in body
Source Link
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''template_redirect', 'my_redirect' );

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' );

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( 'template_redirect', 'my_redirect' );
added 8 characters in body
Source Link
sakibmoon
  • 2.3k
  • 1
  • 19
  • 25
Loading
added 286 characters in body
Source Link
sakibmoon
  • 2.3k
  • 1
  • 19
  • 25
Loading
deleted 17 characters in body
Source Link
sakibmoon
  • 2.3k
  • 1
  • 19
  • 25
Loading
added 122 characters in body
Source Link
sakibmoon
  • 2.3k
  • 1
  • 19
  • 25
Loading
Source Link
sakibmoon
  • 2.3k
  • 1
  • 19
  • 25
Loading