The HTML in the title is escaped because template_preprocess_page() gets the title using the following code:
// Construct page title
if (drupal_get_title()) {
$head_title = array(strip_tags(drupal_get_title()), variable_get('site_name', 'Drupal'));
}
drupal_get_title() then contains the following code:
function drupal_get_title() {
$title = drupal_set_title();
// during a bootstrap, menu.inc is not included and thus we cannot provide a title
if (!isset($title) && function_exists('menu_get_active_title')) {
$title = check_plain(menu_get_active_title());
}
return $title;
}
The title is escaped from that function.
As far as I know, the content of <title>
should not contain HTML tags; that is the reason it is escaped.
In the W3C specifications for HTML 4 is reported the following text:
Titles may contain character entities (for accented characters, special characters, etc.), but may not contain other markup (including comments). Here is a sample document title:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD>
<TITLE>A study of population dynamics</TITLE>
<!-- other head elements -->
</HEAD>
<BODY>
<!-- document body -->
</BODY>
</HTML>
In Changed Elements it's not reported any changes between HTML 5 and HTML 4 about the <title>
tag.
In Drupal 7, you could set the title with drupal_set_title($title, PASS_THROUGH)
, but the documentation says:
Only set to PASS_THROUGH if you have already removed any possibly dangerous code from $title
using a function like check_plain() or filter_xss(). With this flag the string will be passed through unchanged.
PASS_THROUGH
is used to avoid the title is filtered twice, not to filter the title at all.
Then, using drupal_set_title()
is not possible from the title callback; you should set it in a different place. I would not suggest doing so, though.