Add following code in theme "functions.php" file
/*************************************************************************************************************
* Only logged in user can view site except Login, Register, Password-Recovery & successful Registration pages
*************************************************************************************************************/
add_action( 'wp', 'members_only' );
function members_only() {
// Restrict unlogged user
if( !is_user_logged_in() ) {
// id specified page then execute
// 789 is page id for "Registration" page.
// 792 is page id for "Login" page is also Home page.
// 796 is page id for "Password Recovery" page.
// 868 is page id for "Successful Registration" page.
// is_front_page() for website main page.
if (is_page(789) || is_page(792) || is_page(796) || is_page(868) || is_front_page() ) {
// echo "This is current page";
}
else {
// Redirect to Home page.
//wp_redirect( get_home_url() );
wp_redirect( 'https://www.example.com/wp-login.php' );
exit;
}
}
}
0 comments:
Post a Comment