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

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

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

share|improve this question
up vote 0 down vote accepted

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

share|improve this answer
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 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.