Change the template when the user is not logged in using page_template filter (it does not work)
Your code doesn’t really do any “user logged in” check, and you aren’t using a couple of the globals you import. function restrict_access_to_unlogged_users($template) { if (!is_user_logged_in()) { $template = get_stylesheet_directory() . ‘/need-login.php’; } return $template; } add_filter( ‘page_template’, ‘restrict_access_to_unlogged_users’, 20 ); And you could do this more globally with template_include. function restrict_access_to_unlogged_users($template) { if (!is_user_logged_in()) … Read more