get_role is just going to return information about the role. It isn’t going to tell you if the current user has that role. Use wp_get_current_user with a check something like this:
function subscriber_redirection() {
global $redirect_to;
$user = wp_get_current_user();
if (in_array('subscriber',$user->roles)) {
// user has subscriber role
if ( !isset( $_GET['redirect_to'] ) ) {
$redirect_to = get_option('siteurl');
}
}
}
I don’t know why you are using global $redirect_to; but never do anything with the variable.
Related Posts:
- Redirect After Delete User in Backend
- Is it possible to incorporate username in a login redirect?
- Page template that redirects user based on role
- Redirect each user to specific pages based on their role
- Redirect Page ID, based on logged-in User Role
- Conditional redirect on login using referring URL
- Redirecting by role from a button
- Redirect Localhost wordpress site to dashboard
- How to redirect all requests to wp-login.php?
- Index in root, wordpress in subdirectory
- Redirect to “All Posts” after post update or publish in Block Editor
- Redirection errors
- How do I redirect upon login a specific user based on role?
- WordPress CMS – hide content from public while in editing stages
- Redirect to a page after a few seconds
- How to redirect only if page doesn’t exists
- htaccess redirect – directory and subpages to a single page
- Plugin for conditional redirect
- url keeps redirecting to a page
- https multiple redirects
- 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 auto login after registration? [duplicate]
- How to redirect user to a specific page based on username?
- Redirect blog archive into certain format
- htaccess 301 Redirect not working for WordPress site
- Auto-detect the redirect url from the original url
- How can I replace my primary url globally with a parked one?
- WordPress Auto-Redirecting on 404
- My website on checking showing 403 error on HTTP Status [closed]
- Redirecting Pages That No Longer Exist — But Could in the Future
- How do I determine what is causing a redirect for a given page?
- Trouble running local WordPress in Google App Engine
- Empty folder being created by WordPress, breaks site
- !is_admin() condition turns true in admin pages
- How to forward all requests starting with a specific folder name to the same folder
- WordPress index.php seems to perform unwanted redirect 301
- Issue redirecting ‘blog’ to ‘news’ in WordPress using .htaccess
- Custom Login Form – Redirect user to login page if not logged in
- Use two different index pages
- How to redirect from one WP site to another
- Extra Text in URL
- wp_redirect and current_user_can issues
- Redirect /home to home.php
- WP_List_table with form of method=GET redirects to wrong url after submit
- WordPress localhost site always redirect to live site [closed]
- My Cloned WP site keeps redirecting to the old one
- Can’t do 301 Redirect, Why?
- Redirect old query string URLs to new add_rewrite_rule URL
- WordPress Permalink Problem 404
- How can I set up a splash page that is redirected to only one time for the visitor? [closed]
- Is there way to redirect all blog post pages to Home page?
- Temporary Infinite Redirect Loop
- Select post from dropdown and add query args not working
- Trying to map a PURL like url to a page
- A question about .htaccess
- Add new post redirection [closed]
- Blog keeps redirecting to the contact page
- Can’t login to WordPress admin panel after changing domain to use WordPress pages as a fallback from React
- WordPress Pagination – 301 Redirect Issue
- Why do my new WordPress pages redirect to home / staging site?
- WordPress multi domain: page redirect to main domain whenever WordPress do the URL guessing issue
- Puzzled at HTTP/2 301 response header
- Applying ‘middleware’ to a url before redirecting? Does WP have built in mechanism for this?
- How to regenerate RSS feed URL like FeedBurner?
- How to avoid redirect 302 in wordpress to the author pages?
- ErrorDocument 410 gives me back a 302 header
- ERR_TOO_MANY_REDIRECTS when switching from good database to old database
- Redirect to /404/
- WordPress Staging site is redirecting to live and lost the child theme
- Mailjet Email Subscription + Redirect w/ Custom Template Fails
- domain redirects to subdomain
- htaccess Redirect 301 doesn’t work. How to debug?
- how can i find malware code and remove from wordpress site to stop it redirecting to hackers click view pages
- Redirect after plugin activation
- Redirect affecting development folder
- change home_url and site_url but don’t redirect to home_url and site_url on load
- How do I skip wordpress’s 404 handling?
- WordPress multisite and redirect to subpage
- My WordPress site redirects to port 8082
- wp-login.php redirect problem
- Custom, conditional redirect on logout
- International characters in slugs to redirect to
- How to Block WordPress from subdomain?
- login page not working [closed]
- Debugging a redirect loop affecting only certain pages
- WordPress redirect to splash page once a day for the first week
- after logout, get_current_user_id still holds value
- noheader on the user/frontend side
- Solution for WordPress URL structure changes and 301 redirects?
- WordPress redirect from one directory to another but exclude wp-admin and wp-login.php
- How to change Ugly link?
- How to use the HTTP API (wp_remote_get) instead of cURL?
- Redirected You too Many Times and Homepage Not Loading
- When invalid child page entered, WP redirects to next available page instead of giving Page Not Found
- Forward and mask implementation not working,
- Redirect from subdirectory to WordPress plain permalink
- Regex and config for redirecting all URLs, except /wp-admin and /specificpage, to a specific page within the same domain, using the Redirection plugin