Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

My site's contributors are successfully registered.

However, when they log in I want them to be directed directly to the home page of the site on not to their profile, because they do not need it.

Is this possible?

Thank you.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Yes this is possible. You can use the login_redirect filter to do this.

Use the code below in your active theme's functions.php file.

function my_login_redirect( $redirect_to, $request, $user ) {
    //is there a user to check?
    global $user;
    if( isset( $user->roles ) && is_array( $user->roles ) ) {
        //check for contributors
        if( in_array( "contributor", $user->roles ) ) {
            // redirect them to the home page $home_url should contain the home page url
            return $home_url;
        } else {
            return $redirect_to;
        }
    } else {
        return $redirect_to;
    }
}
add_filter("login_redirect", "my_login_redirect", 10, 3);
share|improve this answer
    
Thanks, does this work the same for role: Subscriber? –  p.a. Nov 12 '13 at 11:47
    
yes it works the same way, just replace the role accordingly like if( in_array( "subscriber", $user->roles ) ) { . –  Maruti Mohanty Nov 12 '13 at 11:58
    
Thanks, it works, it needed some time to take effect. –  p.a. Nov 12 '13 at 13:20
    
what do you mean by "it needed some time to take affect?" –  Maruti Mohanty Nov 12 '13 at 13:35
    
It wasnt immediately executed as such on our web server. Maybe due to caching reasons. –  p.a. Nov 12 '13 at 14:04

Your Answer

 
discard

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.