Can't redirect if not logged in (1 post)

  1. scheda
    Posted 4 years ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic