I have a block with the id 'block-block-8'. In my template.php I would like to have a function that changes that block's content so I am able to add a dynamic "back to category link" (category needs to come frome the url) on my products page back to the category page.

Something like this:

function ga2012_block_view($delta = '') {
  $block = array();
  switch ($delta) {
    case 'block-block-8':
      $block = array(
        'content' => '<a href="/order/4/workshops">Back to $_GET["category"]</a>',

  return $block;

Does someone has a working implementation of this code? Please ask me questions if I haven't been clear enough, thanks!

2 Answers 2


You might try with hook_block_view_MODULE_DELTA_alter which:

Performs alterations to a specific block

  • I enabled the PHP filter module and added the PHP code into the block via the admin interface. This works for me.
    – user5706
    Commented Jan 13, 2013 at 15:58

In your case, the best solution is to use hook_block_view_MODULE_DELTA_alter as @Artur explained. But there is another way to to customize a custom bloc programmatically using an update function (inside a .install file) in drupal 7 by using:

$content = 'your new content';

$num_update = db_update('block_custom')
                ->fields(['body' => $content,])
                ->condition('bid', your_block_id, '=')

Your Answer

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

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