If you want to create a login-based website and need to redirect all your visitors to the login page, add this code to your theme’s functions.php file.
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 Ghost mode activated in WP Ghost, the redirect will made to the new login path.