I’m building a WordPress-site, where user needs to log in before access to the blog itself. For now, I’ve used this:
add_action('wp_head','foofunc');
function foofunc() {
if(!is_user_logged_in()) die();
}
However, this way I cannot redirect the user to another url, as output has already started. Is there any way to redirect not-logged-in users to an url?
I would user init but that redirects users in wp-admin too.
Martti Laine
Use the “init” handler together with is_admin() to check if the user is already in the admin panel or not: