You would make use of the login_redirect filter.
The example in the documentation looks a lot like what you are asking:
/**
* Redirect user after successful login.
*
* @param string $redirect_to URL to redirect to.
* @param string $request URL the user is coming from.
* @param object $user Logged user's data.
* @return string
*/
function wpse306427_login_redirect( $redirect_to, $request, $user ) {
//is there a user to check?
if (isset($user->roles) && is_array($user->roles)) {
//check for subscribers
if (in_array('subscriber', $user->roles)) {
// redirect them to another URL, in this case, the homepage
$redirect_to = home_url();
}
}
return $redirect_to;
}
add_filter( 'login_redirect', 'wpse306427_login_redirect', 10, 3 );
You would put this code in a plug-in or in your theme’s function.php.
Related Posts:
- Redirect After Delete User in Backend
- How to target specific user role?
- Is it possible to incorporate username in a login redirect?
- Page template that redirects user based on role
- Redirect Page ID, based on logged-in User Role
- Conditional redirect on login using referring URL
- Redirecting by role from a button
- Disable front end to use as CMS only?
- How to prevent automatic redirection of 404 errors and “incorrect” URLs?
- Redirect Localhost wordpress site to dashboard
- Why is wp_redirect() preferable to a standard PHP header redirect?
- How to redirect a sucessful registration to a page template?
- How to redirect all requests to wp-login.php?
- Index in root, wordpress in subdirectory
- WordPress overriding actual subdirectories
- Redirect to “All Posts” after post update or publish in Block Editor
- Redirect user after login/registration globally
- Redirection errors
- WordPress CMS – hide content from public while in editing stages
- how to do logout redirect to current url
- htaccess redirect – directory and subpages to a single page
- Plugin for conditional redirect
- Redirects from Tumblr to new WP
- Why does multisite bypass WordPress for wp-content, wp-admin, wp-includes and .php files?
- Redirect after users complete profile form
- Redirecting to old domain, tried everything, nothing works
- How to modify the Register link in the login page?
- WordPress redirecting to 127.0.0.1 when accessing the site from a remote device
- Changing “Lost Password Email Link” to custom password reset page
- Redirect a page id url but not the page slug
- Redirect based on parameter in url
- Stop wordpress redirecting www to non-www
- WordPress Global Redirect
- Why does wp_redirect strip out %0A (url encoded new line character) and how do I make it stop?
- htaccess redirect – replace special character
- Redirect Logged In User if page is wp-login.php and $_Get[‘level’] = X
- WordPress url incomplete redirects to first article with that name
- Right hook to redirect frontend visitors while respecting rest api plugins to run first?
- Redirect loop after changing nameserver [closed]
- How to make wordpress folder (/wordpress) redirect to /?
- Changing domain
- How to redirect on login to a specific page if a specific meta user is empty
- Redirecting amp url to non amp url
- How To Redirect /url.html to /url?
- Redirect htaccess does not work correctly with my new wordpress site
- Remove #wpcf7-f2450-o1 with Contact form 7 redirect [closed]
- Redirecting deleted posts url to another WordPress install
- Redirecting to new URL structure and 301
- Blog has an infinite redirect loop
- Custom form redirect after login
- How to redirect only 404 pages with htaccess in WordPress
- How to redirect the frontend of a WordPress site (only)?
- My site is being redirected to itself
- Redirect Attachment Page to Attachment
- Permalinks do not include www subdomain
- Front page is being directed to an unknown site
- Redirect away from page if user is not admin
- Domain redirect to wp-admin/setup-config.php file
- redirect to a child theme based on the town of Internet users in france with the verification of the ip address
- How do I change the home page to the registered user’s profile page
- Conditional Redirect
- Upload Directory question
- 301 Redirect /author/username/ to /profile/username/
- Redirection with a wildcard
- How can I stop redirecting from a search to a taxonomy archive page
- How to return a 410 code for previously published posts now set to draft?
- htaccess redirect not working for wp-admin/edit in site using proxy
- How to access my wordpress application using two URLs?
- Redirect Pending Review Status Preview page url to custom url
- The / location 301-redirects to itself in a loop
- Redirect user from backend to frontend
- Better, more efficient redirecting
- Need to redirect from Apache2 Ubuntu Default Page to home page in wordpress
- WordPress website down with error “redirected you too many times.”
- Make a treatment before the action of the form
- Make custom post type archive for administrator only
- Is it possible to take a new visitor to the site to a disclaimer page and then return them to their previous page?
- How to 301 redirect sub domain post URL to root domain
- Homepage (domain) that redirects user toward two subdomains based on his/her preferred language
- redirect to another page if user has registered successfully
- Too many redirects error when change of base url
- How to redirect new registrars to a custom registration page instead of WP default registration page?
- WordPress redirect users from certain countries to subpage of language version
- When redirecting all URLs to homepage, what exceptions do I need to make?
- Custom Login Plugin Redirects to wp-login.php After Site Migration
- Force SSL on a single page which is used as iFrame
- Redirect from subdomain
- New clone of WordPress site 301 redirects back to orginal site
- How to redirect all pages of a blog to a new blog
- Remove link before another link
- WordPress as a Facebook app
- How to handle expired assets/content when user has direct URL
- Best SEO way to redirect from all “posts” to home url
- Is there a way to redirect people from a page on my .com website to a corresponding page on my .co.uk website if they are in the UK
- How to find out what is causing redirect of static content?
- Where to add wp_redirect on frontend pages?
- Running non-WordPress PHP files
- My pagination creates a redirect
- Want to be able to redirect readers to another wordpress site but still be able to access the back end of current site
- Regex and config for redirecting all URLs, except /wp-admin and /specificpage, to a specific page within the same domain, using the Redirection plugin