Support » Plugins » Can't redirect if not logged in

  • I’m trying to redirect users to the login page if they are not already logged in.

    In my head, this is simple… but when it’s put into action, it’s not working.

    Here’s my code.

    //This function is in a class
    function loginCheck() {
    			if (!is_user_logged_in()) {
    				wp_redirect(get_option('siteurl').'/wp-login.php', 301);
    add_filter("init", array($wpmem, "loginCheck"), 1);

    I’ve also tried “add_action” instead of filter, nothing happens either way.

    Any ideas?

  • The topic ‘Can't redirect if not logged in’ is closed to new replies.