-1

I'm trying to redirect certain users to a part of my site but I cannot seem to make it work... can you take a look at this and tell me what I'm doing wrong?

if ( ! function_exists( 'redirect_after_login' ) ) :
    function redirect_after_login() {
        global $user_ID;
        if ( $user_ID === 4 ) {
            global $redirect_to;
            if (!isset($_GET['redirect_to'])) {
                $redirect_to = get_option('siteurl') . '/stock-de-sexitive/';
            }
   }
}
endif;
add_action('auth_redirect', 'redirect_after_login');

Also, I know globals are dangerous, so if you know of a canonical approach that would be great too

0

Try wp_redirect(). And don't forget to exit.

  • Yeah, I did something like that and it worked, may I ask you about the exit? what did you mean by that? – user5057 Jul 16 '11 at 0:56
  • Add exit; after the redirect. Else you'll end in an endless loop. – kaiser Jul 16 '11 at 1:10

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.