This CodeLet will display a block content in a region programmatically. You have to implement hook_preprocess_HOOK() in THEMENAME.theme file of your theme directory.

CodeLet
<?php
/**
 * Implements hook_preprocess_HOOK() for HTML document templates.
 *
 * Add block in a region.
 */

function THEMENAME_preprocess_html(&$variables) {

$block = \Drupal\block\Entity\Block::load('YOUR_BLOCK_ID');
         
$block_content = \Drupal::entityManager()
          ->
getViewBuilder('block')
          ->
view($block);
 
         
$variables['page']['YOUR REGION'][] = $block_content;
}
?>
Compatibility
Submitted by saru1683 on