I have a responsive website which is accessed via login only. When the user logs in they are taken to 'Page 1' (and it is set as the front page).

I would like mobile users to be redirected to 'Page 2' on login. I've found a function which checks if they're using a mobile but it won't let me access 'Page 1' as it redirects back to 'Page 2'.

This is the function:

function so16165211_mobile_home_redirect(){
  if( wp_is_mobile() && is_front_page() ){
     wp_redirect( 'http://www.mywebsite.com/page-2' ); 
add_action( 'template_redirect', 'so16165211_mobile_home_redirect' );

Is it possible to modify this so it only redirects the mobile user once they've logged in as I'd still like them to access 'Page 1'.

1 Answer 1


You can use login_redirect hook. For example:

add_filter('login_redirect', function($to, $request, $user)
    if ( wp_is_mobile() ) $to = admin_url('profile.php');

    return $to;
}, PHP_INT_MAX, 3);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.