2

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

2
  • 2
    try the absolute url: bloginfo('wpurl').'/public';
    – kaiser
    Sep 19, 2011 at 15:27
  • or home_url('/public') Apr 5, 2012 at 23:12

1 Answer 1

3

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.

1
  • If this answer answers your question, you should accept it, by clicking the checkmark beneath the answer up/down vote arrows. Aug 20, 2012 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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