Force redirect not logged in user to (wp-login.php or wp-admin) for specific page
The template redirect is most useful for managing the output of theme files. To redirect a non-logged in user when the page loads, attach your function to the ‘init’ hook. (If you call it sooner than that in the stack, you may get an error because the function definition hasn’t been included yet.) In short, … Read more