Display Drupal 7 block anywhere

Submitted by shiv on Thu, 12/24/2015 - 15:55

Ever wanted to show a Drupal block anywhere in your theme? Use the following code snippet, take note that you will need the module of the block and itsĀ delta

// Load the block region based on module and delta key.
$_your_block = _block_get_renderable_array(_block_render_blocks(array(block_load('MODULE', 'DELTA'))));
// Now we display it.
print render($_your_block);
Another way of doing is..

$block = module_invoke('MODULE', 'block_view', 'DELTA');
print $block['content'];

Sample blackbox block

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas non porta odio, id mattis erat.

Nam sed tincidunt eros. Donec a venenatis odio, vitae commodo sem. Vivamus ullamcorper pellentesque erat, in adipiscing tortor scelerisque sit amet. Nulla pulvinar urna magna. Vivamus a ipsum lorem. Etiam adipiscing pulvinar lorem.