php - Wordpress Guest Login Redirect on view posts -


i have wp site , try force guest login/register before viewing single posts.(not pages, archives etc.).

i have function:

// redirect users arent logged in... function login_redirect() {      // current page     global $pagenow;      // check see if user in not logged in , not on login page     if(!is_user_logged_in() && $pagenow != 'wp-login.php')           // if user is, redirect login form.           auth_redirect(); } // add block of code above wordpress template add_action( 'wp', 'login_redirect' ); 

the problem function redirects guest login when view page/post/etc. can me modify function redirect on viewing single posts? thanks, iasmina

try this:

   function login_redirect() {    // current page    global $pagenow;     // check see if user in not logged in , not on login page          if (!is_user_logged_in() && $pagenow != 'wp-login.php' && is_single() && !is_home()) {                   auth_redirect();        } }  // add block of code above wordpress template add_action('wp', 'login_redirect'); 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -