I want to show a custom link for each role on my site. To do so, I will put PHP code in my page.tpl.php. I want to add an if statement that checks if the current user's role is equal to something, then print the link.

How can I get the current user role?

  • 1
    Putting PHP in page.tpl.php violates Drupal programming style, of-course the extendibility of your theme. Better way is to make a block and give permission to it through block configuration page. – niksmac Apr 17 '12 at 4:48
global $user;
if($user->roles[1] || $user->roles[2]){
//Do Something
  • The code just check the user has two roles; whatever they are are, the control statement is executed. – kiamlaluno Apr 17 '12 at 4:42
  • Has either* role – Brock Hensley May 8 '14 at 20:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.