Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

If user enters the url in the browser and he is not logged in, then we want to redirect him to How can I do this within WordPress?

share|improve this question

1 Answer 1

function redirect_user() {    
   if ( $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] == '' ) {
        if ( ! is_user_logged_in() ) {
           wp_redirect( '' );
add_action( 'init', 'redirect_user' );

Do you mean something like this?

share|improve this answer
But this need to be added into a function, and this function should be added before an action right? something like this: add_action('some_action', 'this_function'). What should be that 'some_action'? – Joshua Sep 24 '12 at 19:53
I think it's ok on init, I've updated the code. – Ryan Koehler Sep 24 '12 at 20:03

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.