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

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?

share|improve this question
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/' );
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.