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

Because it's not working for me. This code checks if a user has just registered. I want to redirect him to a custom page if so. Otherwise, redirect him to the homepage or admin page.

function mylogin_redirect($redirect_to, $url_redirect_to = '', $user = null) {
    if( $user->ID ) {
        $user_info = get_userdata( $user->ID ); 
        // If user_registered date/time is less than 48hrs from now
        // Message will show for 48hrs after registration
        if ( strtotime( $user_info->user_registered ) > ( time() - 172800 ) ) {
            return get_bloginfo('url') . "/custompage/";
        } elseif( current_user_can( 'manage_options' )) {
            return admin_url();
        } else {
            return get_bloginfo('url');
add_filter('login_redirect', 'mylogin_redirect');

I get the expected results for the two options but the admin. elseif( current_user_can( 'manage_options' )) { return admin_url(); } doesn't seem to get parsed.

share|improve this question
up vote 6 down vote accepted

Probably because the global $current_user isn't valid yet, which is used by current_user_can().

However, you can use this instead;

if ($user->has_cap('manage_options')) { return admin_url(); }
share|improve this answer

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.