If you want to create a login based website and you need to redirect all your visitors to login page, please add this code in your theme’s functions.php file.

Solution 1

function protect_whole_site() {
   if (!is_user_logged_in()) {
     if (isset($_SERVER['REQUEST_URI'])) {
        $url = untrailingslashit($_SERVER['REQUEST_URI']);
        if (strpos($url, HMWP_Classes_Tools::getOption('hmwp_login_url')) === false) {
           wp_redirect(site_url('wp-login.php'));
           exit();
        }
    } else {
        wp_redirect(site_url());
        exit();
    }
  }
}
add_action('template_redirect', 'protect_whole_site');

If you have Ninja mode activated in Hide My WordPress, the redirect will to the new login path.

 

Solution 2

If you want to redirect all the logged subscribers to front-end you need to add this code in your theme’s functions.php file.

function no_dashboard() {
   if ( current_user_can( "subscriber" ) ) {
       wp_redirect(home_url()); 
       exit();
   }
}
add_action('admin_init', 'no_dashboard');

In this case, the subscribers will not see your WordPress dashboard which is a good security workaround.