How do I display a CMS static block in my Magento header

How do I display a CMS static block in my Magento header

September 20, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How do I display a CMS static block in my Magento header

Displaying CMS Static Blocks in Magento Header Template

In Magento, displaying static blocks in your header template allows you to easily manage and update dynamic content across your storefront without editing themes or templates directly. Here’s a step-by-step guide on how to display a CMS static block in the header of your Magento store.

Understanding Magento Static Blocks

Static blocks are reusable chunks of content that can be managed through the admin interface. They allow you to define HTML, CSS, and JavaScript snippets that can be included in various locations throughout your store using block references or template calls.

Creating a New Static Block

To get started, navigate to Admin > CMS > Static Blocks and click on Add New Block. Fill in the required fields:

  • Title: A unique identifier for the block.
  • Identifier: The technical name used to reference this block in your templates. It should be unique within your namespace (e.g., vendor_module.block_name).
  • Content: The HTML content of the static block.

Click on Save Block when you’re done.

Displaying a Static Block in the Header

To display a static block in the header, you’ll need to edit your theme’s template files. By default, most themes use the Luma theme as a base. In your theme folder (usually located at app/design/frontend/Your_Vendor/Your_Theme), look for the Magento_Theme module.

In your theme, navigate to: app/design/frontend/{vendor}/{theme}/Magento_Theme/templates/html/header.phtml

Open this file in an editor and locate the following line near the bottom of the file:

<?= $block->getChildHtml('top.links') ?>

This line calls the top.links block, which is responsible for displaying links in the top-right corner of the header. To insert our new static block below this link section, we’ll modify the line as follows:

<?= $block->getChildHtml('top.links') ?>
<div class="custom-static-block">
    <?= $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('<your_block_identifier>')->toHtml() ?>
</div>

Replace <your_block_identifier> with the identifier of your static block.

Flushing Cache and Checking Your Work

After making these changes, save the file. Next, you’ll need to flush the Magento cache for your modifications to take effect:

  1. Log in to your admin panel.
  2. Navigate to System > Cache Management.
  3. Select all cache types or choose Configuration from the dropdown menu.
  4. Click on Flush Magento Cache.

Now, when you visit your storefront, you should see the content of your static block displayed below the top-right links in the header area.

Conclusion

Displaying CMS static blocks in your Magento header template allows for dynamic and easily manageable content across your store. By following this guide, you can now insert custom content, promotional messages, or even third-party widgets into your header with minimal effort.

Extensions Themes Admin JavaScript

Our network