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, 2012 at 4:48

1 Answer 1

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.
    – apaderno
    Apr 17, 2012 at 4:42
  • Has either* role May 8, 2014 at 20:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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