Unable to update head_title string in template_preprocess_html I wanted to add some data to the page head title and created a template_preprocess_html function in my module.

I added a couple entries to the head_title_array and imploded the array back into head_title.

At first it looked like it wasnt working at all, but then I checked and in html.tpl.php the $head_title_array was updated.

My temp solution is to implode the array there before printing it but that's a little hackish for me.

Thoughts on where the title is being set or re-set to prevent it from being changed in template_preprocess_html?

Module code is aproximately:

function MODULE_preprocess_html(&amp;$variables) {
  $head_title = $variables['head_title_array'];
  array_unshift($head_title, 'TEST');

  $variables['head_title_array'] = $head_title;
  $variables['head_title'] = implode(' | ', $head_title);
}


and in html.tpl.php:

&lt;title&gt;&lt;?php print implode(' | ', $head_title_array); ?&gt;&lt;/title&gt;


I just noticed that the metadata module is storing variables in an array called metatag_set_preprocess_variable.  That might be the cause, I'll investigate further.
If you find that $head_title is different from implode(' | ', $head_title_array), it means there is a module running after yours that implements hook_preprocess_html() which runs after your implementation, or hook_process_html().

The code executed from Drupal is the following:


template_preprocess_html() (It runs before hook_preprocess_html().)

// Construct page title.
if (drupal_get_title()) {
  $head_title = array(
    'title' =&gt; strip_tags(drupal_get_title()), 
    'name' =&gt; check_plain(variable_get('site_name', 'Drupal')),
  );
}
else {
  $head_title = array('name' =&gt; check_plain(variable_get('site_name', 'Drupal')));
  if (variable_get('site_slogan', '')) {
    $head_title['slogan'] = filter_xss_admin(variable_get('site_slogan', ''));
  }
}
$variables['head_title_array'] = $head_title;
$variables['head_title'] = implode(' | ', $head_title);

// Populate the page template suggestions.
if ($suggestions = theme_get_suggestions(arg(), 'html')) {
  $variables['theme_hook_suggestions'] = $suggestions;
}

template_process_html() (It runs after hook_preprocess_html(), but before hook_process_html().)

There is no code that alters $variables['head_title_array'], or $variables['head_title'].


The fact $head_title_array contains the value you expect makes me think there is really a module that implements hook_preprocess_html to alter $variables['head_title'].

To be sure your module is the last one running hook_preprocess_html(), you need to make your module weight higher.