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

I have a mobile version of my website at mywebsite.com/mobile and there is a login form which posts to wp-login.php.

Currently, when users login from the homepage, they are redirected to their Buddypress profile if they are not admin.
I would like to keep this in place if they login from the home page, but, if they login from mywebsite.com/mobile, I would like them to be redirected to mywebsite.com/mobile/dash.

add_filter( "login_redirect", "bpdev_redirect_to_profile", 10, 3 );

function bpdev_redirect_to_profile( $redirect_to_calculated, $redirect_url_specified, $user )
    /* If logging in from website.com/mobile, 
       which has a login form which posts to wp-login.php, 
       redirect to website.com/mobile/dash
    if( empty( $redirect_to_calculated ) )
        $redirect_to_calculated = admin_url();

    /* If the user is not site admin,redirect to his/her profile*/
    if( !is_site_admin( $user->user_login ) )
        return bp_core_get_user_domain( $user->ID );

    /* If site admin or not logged in,do not do anything much */
        return $redirect_to_calculated; 
share|improve this question

Adding a conditional check such as,


   $current = "http://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    $mobile = "http://www.example.com/mobile";
    if($current == $mobile) {
        //redirect to desired location
I'd provide more detail but am currently on mobile, so it's difficult to write. See how you fair with the above.

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.