Insert a block programmatically with Drupal

Block is generated by a view

$block = module_invoke('views', 'block', 'view', <view_name not quoted: this is The unique identifier of the view>);


$block = module_invoke('views', 'block', 'view', list_all_providers_cat_map);
print $block['content'];

The above does work for Drupal 5 but it doesn;t look like is working for Drupal 6 so you can just embed the view.

print views_embed_view('most_read_today', 'block_1');

If you need the title then use

$view = views_get_view('most_read_today');
$output = $view->preview();
$title = $view->get_title();
print '<div class="title">' . $title . '</div>';
print $output;

User created block

$block = module_invoke('block', 'block', 'view', <block id>);


$block = module_invoke('block', 'block', 'view', 20);
print $block['content'];

Block is generated by a module

$block = module_invoke(<module name>, 'block', 'view', <block id>);


$block = module_invoke('google_admanager', 'block', 'view', 0);
print $block['content'];

NOTE: How to find the block ID.

Go to the list of blocks ( /admin/build/block ) and hover the mouse over the configure link.  For a user created block you'll see /admin/build/bloc/configure/block/<id> and for a module created block you'll see  /admin/build/bloc/configure/<module name>/<id>

Please notice that it is the same syntax so to speak because in the case of the user created block the module name is block since it is the block module that creates it.

Drupal 7 Views Block

$block = module_invoke('views', 'block_view', 'testimonials-block');
print render($block);