HTML In a hook_menu title callback I'm trying to insert a span class around some text in title callback. It passes through a t() function so all the html is escaped. 

Is there a way round this?

My code is:

function custom_module_menu() {
  $items = array();

  $items['discussion'] = array(
    'title' =&gt; 'Discussion',
    'title callback' =&gt; 'custom_module_title',
    'page callback' =&gt; 'custom_module_tester1',
    'access callback' =&gt; TRUE,
    'menu_name' =&gt; 'document-menu',
    'type' =&gt; MENU_NORMAL_ITEM,
    'options' =&gt; array('attributes' =&gt; array('class' =&gt; 'discussion')),
    'weight' =&gt; 10,
  );

  return $items;
}
function custom_module_title() {
  $discussionnid = custom_module_postexist(3);
  if ($discussionnid) {
    return 'Discussion &lt;span class="discussionnumber"&gt;85&lt;/span&gt;';
  }
  else {
    return 'Discussion';
  }

}
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) &amp;&amp; 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 &lt;title&gt; 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:

&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;HTML&gt;
&lt;HEAD&gt;
&lt;TITLE&gt;A study of population dynamics&lt;/TITLE&gt;
&lt;!-- other head elements --&gt;
&lt;/HEAD&gt;
&lt;BODY&gt;
&lt;!-- document body --&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;



In Changed Elements it's not reported any changes between HTML 5 and HTML 4 about the &lt;title&gt; 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.