Magento – Magento 2: How to call Widget programatically

layoutmagento-2.1.4themewidget

I have created widget

Type: CMS Static Block
Theme: My Theme
Display on: All Pages
Container: CMS Footer Links
Template: CMS Static Block Default Template
Widget Options: Block (My selected block)

It display my block content on Footer.

Above settings work fine in default Magento 2.1.4 CE, but it's not working on my Porto Theme.

So how to manually call my Widget in my Theme i think Theme's default.xml or in .phtml file or in My Custom Module?

Best Answer

You can created the Widget in Block in admin panel and use in the .phtml file using below code:

<?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('block_identifier')->toHtml();?>