I want to get a <br> tag into a block-title but by default the brackets are turned into html characters. My theme's block.tpl is

<h2<?php print $title_attributes; ?>><?php print $block->subject; ?></h2>

so it looks like the rendering isn't happening there. I can't find where $block->subject is getting processed. It's not in my theme's template.php. So where in core is $block->subject assembled?

4 Answers 4


You may be interested in Block Class Styles, which has an additional feature:

Allows the ability to set a global text format for custom block titles; this allows you to now have HTML in your custom block titles. Yes, you can now have block titles that contain HTML markup!


Found the line in block.module:

$block->subject = $block->title == '<none>' ? '' : check_plain($block->title);

Decided to skip any fanciness and just replace $block->subject with $block->title in my block.tpl.php. Easy.

  • 2
    careful. Core does this to disallow HTML in block titles -- this is to avoid an authorized user from creating content that contains HTML to cross-link titles to malicious domains.
    – tenken
    Jan 14, 2013 at 19:25
  • Thanks, yes. This is for a site with only trusted users. Is there a better filter for html that still lets <br> tags through?
    – alexvance
    Jan 14, 2013 at 19:40
  • 3
    Drupal doesnt care about "trusted users". It assumes everyone is potentially malicious -- because your site could be hacked and an un-trusted user could submit a blog post, or create a block for instance. Dont get me wrong -- I've done something similiar for a project as well. As a CMS drupal sanitizes all "titles" that come from user input.
    – tenken
    Jan 14, 2013 at 20:05
  • Right, that's what I meant - the users are trusted by me, not necessarily Drupal. :)
    – alexvance
    Jan 14, 2013 at 20:27

i went this route without having to hack core or install another module. this solution is good if you just need to insert a limited amount of html. in my case i just wanted to surround the text with an em> tag for styling purposes.

i made a new tpl file to override block.tpl.php in my templates folder and I added in the following:

<div id="<?php print $block_html_id; ?>" class="<?php print $classes; ?>"<?php print $attributes; ?>> 

  <?php print render($title_prefix); ?>
<?php if ($block->subject): ?>
  <h2<?php print $title_attributes; ?>> 


  $xtitle = preg_replace('/\*\*/', '<em>', $block->subject, 1); 
  $xtitle = preg_replace('/\*\*/', '</em>', $xtitle, 1); 

  print $xtitle; 


<?php endif;?>
  <?php print render($title_suffix); ?>

  <div class="content"<?php print $content_attributes; ?>> 
    <?php print $content ?>

All I'm doing is just doing a string replacement for * * . Now i can just surround my titles with ** if i want to add the em> tag.


You can add an if or switch statement at the top of block.tpl.php to match the unique block delta and then you can change the value of $block->subject:

if($block->delta == 'BLOCK_DELTA'){ $block->subject = t('A title with some HTML'); }

Install devel and the use kpr($block->delta); to find out what the delta is.

Don't forget to pass the title through the t function.

Your Answer

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

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