最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Page template that redirects user based on role

programmeradmin1浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

You 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);
发布评论

评论列表(0)

  1. 暂无评论