WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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' );

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!



share|improve this question
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
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") );

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

Your Answer


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.