HTML5 block-level links for Drupal blocks

If you find yourself wanting to link the entire content of a block in your Drupal 7 site, try this recipe. Note that this is only valid markup if you're using an HTML5 doctype. For more on block-level links, see the write-up on HTML5 Doctor.

First, install the Block Title Link module. Once enabled, you should see a new fieldset on all your block edit forms.

Block Title Link fieldset

Then edit your theme's block.tpl.php template. You may need to copy block.tpl.php from modules/block/block.tpl.php or your parent theme.

<?php /* Replace this: */ ?>

<?php print $content; ?>

<?php /* With this: */ ?>

<?php if (isset($block->title_link)): ?>
  <?php print l($content, $block->title_link, array('attributes' => array('title' => $block->title_link_title), 'html' => TRUE)); ?>
<?php else: ?>
  <?php print $content; ?>
<?php endif; ?>

Clear your cache if you didn't already have a block.tpl.php in your theme, and you're done.

You could also link only the content of the block and not the title of the block by unchecking "Display Link". Many possibilities here.

This could very easily be adapted for Drupal 6 as well. I believe the main difference would be $block->content instead of $content in your block template.