0

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

3
function redirect_user() {    
   if ( $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] == 'www.abc.com/' ) {
        if ( ! is_user_logged_in() ) {
           wp_redirect( 'http://www.abc.com/de/' );
           exit;
        }
    }
}
add_action( 'init', 'redirect_user' );

Do you mean something like this?

  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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