Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This sounds dead bang simple, but I just can't figure it out.

I want the following functionality:

If user is not logged in and they try to access anywhere on the site (including the homepage) - send them to a specific page.

I tried, adding the following but received a "not redirecting properly" message:

if (!is_user_logged_in() ) {
 wp_redirect ('/public' );
 exit;
 }

I guess if I can add a clause to the if statement saying and the page I am accessing is not the public page, but I'm not quite sure how to that properly.

Any plugins that I see out there redirect to the wordpress login screen.

Any help is greatly appreciated!

Thanks,

MG

share|improve this question
2  
try the absolute url: bloginfo('wpurl').'/public'; –  kaiser Sep 19 '11 at 15:27
    
or home_url('/public') –  chrisguitarguy Apr 5 '12 at 23:12
add comment

1 Answer 1

up vote 2 down vote accepted

The reason why you are getting a not redirecting properly message is because you are creating an endless loop of redirects. They get redirected to /public but because they are not logged in they get redirected again and again and again...

Try this code instead:

if( ! is_user_logged_in() && ! is_page("public") )
{
    wp_redirect( site_url("/public") );
    exit;
}

I'm assuming that /public is a page you have setup.

share|improve this answer
    
If this answer answers your question, you should accept it, by clicking the checkmark beneath the answer up/down vote arrows. –  Chip Bennett Aug 20 '12 at 15:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.