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 user to original url after login?
- Redirect to dashboard after login
- Make a video post redirect to next post after completion
- WordPress site redirects to different wordpress domain on the same server after reuploading db backup
- WordPress Redirect based on the prescence of a cookie
- Random and Erroneous WordPress Redirect
- Redirect Old domain & posts to new domain homepage
- Redirecting users to referrer page after logging in using custom login form
- Remove lost password form and URL
- wordpress custom login successful redirect hook
- What is the wordpress way of displaying local external content?
- How To Only Allow Users To View Their Own Buddypress Profiles? [closed]
- htaccess redirect dynamic posts
- Menu links only using http after enabling https, unable to redirect http links
- Redirect all pages to homepage but still allow dashboard
- some url does not redirect from http to https
- Why can’t I access files / directories outside of wordpress
- Return to where the user was, after log out
- 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 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?
- WordPress url incomplete redirects to first article with that name
- Create a page that automatically redirects to latest post of a specific tag/category?
- How to make wordpress folder (/wordpress) redirect to /?
- Changing domain
- Redirect htaccess does not work correctly with my new wordpress site
- Redirecting deleted posts url to another WordPress install
- Redirect – remove custom query string
- Custom redirect user after login based on metadata
- wp_redirect () doesn’t work in nginx?
- Add Username to URL for redirect
- Have WordPress post redirect to url when accesed from iPad (Safari)
- Adding query string parameters to URL with same name as custom post type gives 404 error
- Display Freebie Page Content only if Referrer is from Form Page
- Dynamic redirect
- Create header.php redirect in WordPress and with WPML
- simple wordpress form redirection
- Forced Redirect on a server migration
- Site Address and WordPress Address settings when using a load balancer
- Cannot install wordpress, /wp-admin/install.php, inproper redirection [closed]
- Prevent “/login” to redirect to “/wp-login”
- Redirect home resets (qtranslate) language
- How to redirect logged out users to specific page?
- Redirect certain pages if user logged in
- Redirect to post_id?
- wp_login_form redirect
- Date based redirects of posts that no longer exist
- How can I disable redirect domains?
- When i try to enter subdomain i’m redirected to main domain
- Change my URL from https://www.domain.com to https://domain.com
- redirect wordpress post to new subfolder site on same domain
- 301 all old pages to new location
- Use a 301 to Redirect any 404 from at the blog post level to the blog archive
- How do I share a site only to one User at the time? Please help π₯Ίπ
- Need to redirect home page only on Woocommerce site if user logged in
- Redirect to dashboard user once you click on Publish page
- Author Archive Page redirecting issue
- Understanding Redirects
- Random redirect to wp-admin/install.php
- Changing auth_redirect() page
- Why https://www. SUBdomain is redirected by WP to https://MAINdomain
- Page editing in backend redirecting to 404 page not found with url /post.php
- Redirect based on referer using Advanced Custom Fields
- Redirect User to Specific Page
- How to redirect a referal url to a signup page?
- How to modify the WordPress comes with redirect
- On login redirect to different homepage if user is using a mobile
- Multisite hide subdirectory
- WordPress update 4.4.1 redirect loop
- Redirecting Issue
- Redirect user to login and then to page where they came from
- htaccess and redirect to new url using regex
- How to redirect correctly a root domain to a subdomain in a subfolder?
- redirect attachment page to category page
- 301 redirect for wordpress permarlink
- login_redirect for Mobile Web
- Need rewrite for URL with specific string
- Redirect to 404.php from single.php
- How to make my homepage automatically redirect to an external website?
- How does the flow of htaccess files in sub-directories work
- Redirect to a subdirectory frontpage using without using a WP plugin- what files to edit, and how?
- How to Show different page URL instead of default home page URL
- How to Redirect Url to homepage?
- 404 Not Found with All Cloaking plugins
- Stopping media file redirects
- How to redirect users without permission to view content to a custom page?
- redirect the root of a domain, while leaving the www version unredirected
- How to Create Custom Route to a page in WordPress
- How to create a redirect to another domain like safe redirect manager from php
- Post Migration Site Migration Redirects All Known Solutions Attempted