Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I need to dynamically change the Drupal site title to match the role the current use has, or as an alternative option I need to be able to change it based on the content type that is being viewed (on my installation, each role has it's own content). How can i do that? I'm using Drupal 6

share|improve this question
    
Just to clarify: do you mean the page title that appears at the top of the browser window? Could you show an example how it would need to be changed? –  Dooshta Mar 12 '12 at 21:39
    
@Dooshta I am talking about the value you set in Drupal at Admin > Site configuration > Site information > Name. This value is static and is the same on the whole site, instead i need it to be dynamic, and change based on user role and/or content type –  Terix Mar 13 '12 at 9:37
add comment

3 Answers

As much as I know the site name is being output with $site_name in a basic Drupal 6 page.tpl.php file and is also part of the $head_title variable. To change them dynamically you could use template_preprocess_page() in your template.php file. Assuming you want to change one or both of those variables based on the user role you could use the following example:

function mytheme_preprocess_page(&$variables) {
  global $user;
  if (in_array('administrator', $user->roles)) {
    $head_title = explode(' | ', $variables['head_title']);
    $head_title[1] = 'Title for admin';
    $variables['head_title'] = implode(' | ', $head_title);
    $variables['site_name'] = 'Site name for admin';
  }
}

Both the head title and site name variables are modified for the 'administrator' role in this case. It should be relatively simple to make this work for all roles the way you want if writing some custom code is not an issue.

share|improve this answer
add comment

The Page Title Module along with Token Module might help you achieve that.

share|improve this answer
    
Could you describe how? I don't recall conditional tokens. –  Mołot Jul 30 '13 at 7:54
add comment

I wanted to do something similar but append text to the Site Name

function mytheme_preprocess_page(&$variables) {
  global $user;
  $sitename = variable_get('site_name', '');

  if (in_array('administrator', $user->roles)) {
    $variables['site_name'] = t('!sitename for Admins', array('!sitename' => $sitename));
  }
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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