I'm building a multisite and have encountered an issue that I can't find a solution to.
When users log into a subsite, for example at "example.com/site2/wp-admin", they are redirected to "example.com" when they sign in.
Is there a way to ensure that users remain on the subsite to which they are logging in?
CodePudding user response:
WordPress default functionality works fine for redirecting to each subsite after login but in your case, something conflicts with redirection after login.
So first you to go network setup page from the network admin dashboard and copy the .htaccess code and replace that.
Still, the same issue so put the below code in your function file.
add_filter('login_redirect', 'login_redirect_subsite', 10,3);
function login_redirect_subsite($redirect_to, $request, $user) {
$site_id = get_current_blog_id();
$current_site = get_blog_details($site_id);
$blog_url = $current_site->siteurl.'/wp-admin';
return $blog_url;
}