Redirect visitors to login page if visitor/user not logged in:
Simply add the below PHP code into any of plugin Main File
or into your active theme function.php
file
function is_login_page() {
if ( $GLOBALS['pagenow'] === 'wp-login.php' && ! empty( $_REQUEST['action'] ) && $_REQUEST['action'] === 'register' )
return true;
return false;
}
function redirect_visitors_to_login() {
//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
wp_redirect( wp_login_url() );
exit;
}
}
add_action( 'template_redirect', 'redirect_visitors_to_login' );
Hope this will work for.
Thanks
(referance)
-
This reply was modified 7 years, 11 months ago by
weblizar. Reason: code referance added
-
This reply was modified 7 years, 11 months ago by
weblizar.
-
This reply was modified 7 years, 11 months ago by
weblizar.
-
This reply was modified 7 years, 11 months ago by
weblizar.