Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress force user to login before view any site content

In wordpress I am trying to force user login first before see anything. Means I want my user to first login to view any single page, post or archive and only they can se FAQ page. I am trying with below code but problem is as soon as I loged in, its redirect me again to login page.

However my site structure would be like below and in same manner I want this code to work...

// Force user to login on welcome
function my_force_login() {
global $post;

    if (is_single() || is_front_page() || is_page() && !is_page('login') && !is_user_logged_in()){ 
        auth_redirect(); 
    }   
}

Welcomd-Login screen (like facebook) -Home page -Blog -About -contact -FAQ

So I want to allow visitor only can see Welcome Login screen and FAQ, contact page to view rest of the site I want to force them to login..

I need great help of you people.. Thanks a lot in advance..

like image 929
Code Lover Avatar asked Dec 19 '11 16:12

Code Lover


2 Answers

I think you are missing a parenthesis:

if ( ( is_single() || is_front_page() || is_page() ) 
       && !is_page('login') && !is_user_logged_in()){ 
    auth_redirect(); 
} 
like image 141
bingjie2680 Avatar answered Sep 19 '22 05:09

bingjie2680


There's a plugin you can use for this. Private Only

like image 43
Tim Avatar answered Sep 20 '22 05:09

Tim