0

Can someone help me with this? I am using wordpress and create an html tag to create a link. I wanted to know if it is possible that this link redirects users according to their role. I understand that for this I must use php but I could not find the proper code. This is what I could do but it does not work.

<?php 
$current_user = wp_get_current_user(); 
$role_name = $current_user->roles[0]; 
if ('vendor' === $role_name) { wp_redirect(get_site_url() . '/dasboard'); exit(); 
if ('customer' === $role_name) { wp_redirect(get_site_url() . '/my-acount'); exit(); 
?>
  • 1
    SO is not a tutorial site, so you are not going to get any traction here. Why not do some research and figure out the basics and then come back if you have a specific question about code you've written. –  Nov 14 '18 at 17:34
  • [Edit] the question and put your [mcve] in there, formatted as code. (Comments are not part of the Q&A, and can be removed.) –  Nov 14 '18 at 19:29
  • That's OK? I do not understand the platform yet, I hope you can understand. Thank you – Santiago Tomas Castillo Nov 14 '18 at 19:39
  • Make sure you take the [tour] and read [ask] to get an idea of how this site is different from most other sites. –  Nov 14 '18 at 19:41
  • Refs: https://code.tutsplus.com/tutorials/redirect-users-to-custom-pages-by-role--wp-33505 http://thedigilife.com/wordpress-redirect-user-to-custom-page-based-on-user-role/ Maybe a duplicate: https://stackoverflow.com/q/35066069/1531971 (If the latter does not work for some reason, it'll be your job to tell us so, and then show what steps you've taken to debug/research the problem.) –  Nov 14 '18 at 19:42

0 Answers0