I'm trying to come up with a wordpress page template (acting as a landing page) that redirects a user to another page based on their role.
ex.
user with role editor goes to landing page and is redirected to "/editors-page/"
user with role subscriber goes to landing page and is redirected to "/subscribers-page/"
I've come across so many plugins and custom functions that talk about redirecting at login but I'm using multisite and there are some complications using any of those examples so I've landed on the above solution.
Any help would be wonderful! Thanks so much!
I'm trying to come up with a wordpress page template (acting as a landing page) that redirects a user to another page based on their role.
ex.
user with role editor goes to landing page and is redirected to "/editors-page/"
user with role subscriber goes to landing page and is redirected to "/subscribers-page/"
I've come across so many plugins and custom functions that talk about redirecting at login but I'm using multisite and there are some complications using any of those examples so I've landed on the above solution.
Any help would be wonderful! Thanks so much!
Share Improve this question asked Sep 23, 2019 at 16:18 user3311868user3311868 134 bronze badges1 Answer
Reset to default 0You can use current_user_can()
to check the user roles. https://developer.wordpress/reference/functions/current_user_can/
To check if the user is editor or administrator:
<?php if( current_user_can('editor') || current_user_can('administrator') ) { ?>
// Stuff here for administrators or editors
<?php } ?>
Then to redirect you can use this:
header('Location: '.$newURL);