Create your own custom Drupal block programmatically
Super duper simple example on how to programmatically create your own custom Drupal blocks and display any content.
Code snippet below needs to be in a custom module.
/**<br> * Implements hook_block_info().<br> */<br>function YOUR_MODULE_block_info() {<br> $blocks = array();<p> $blocks['YOUR_BLOCK_ABC'] = array(<br> 'info' => t('YOUR BLOCK NAME'),<br> );</p><p> return $blocks;<br>}</p><p>/**<br> * Implements hook_block_view().<br> */<br>function YOUR_MODULE_block_view($delta = '') {<br> $block = array();</p><p> switch ($delta) {<br> case 'YOUR_BLOCK_ABC':<br> $block['subject'] = '';<br> $block['content'] = _YOUR_MODULE_BLOCK_ABC_CONTENT();<br> break;<br> }</p><p> return $block;<br>}</p><p>function _YOUR_MODULE_BLOCK_ABC_CONTENT() {<br> $output = t('Hello world');<br> return $output;<br>}</p>
Tags: drupaldrupal 7blockprogrammaticallycustomhook_block_info