Magento 1.9: Add custom block to header

Magento 1.9: Add custom block to header

July 28, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento 1.9: Add custom block to header

Solving Magento 1.9 Header Block Issues

Hello, developers! Today I’m going to help you resolve an issue that many of us face while working on Magento 1.9 projects - adding custom blocks to the header using local.xml. Let’s dive into a common problem and find out why your code isn’t appearing as expected.

The Issue: Custom Header Block Not Displaying

You’ve correctly defined a block in your local.xml file:

<reference name="header">
    <block type="core/template" name="wc-customheadblock" template="wc-customheadblock.phtml" />
</reference>

And you’ve created the corresponding PHTML file with some simple content:

<div style="height:100px; background-color:green">
  <h1>This is the wc custom head block</h1>
</div>

However, the header remains blank and your custom block isn’t showing up. You’ve confirmed that adding blocks to sidebars works perfectly fine using the same approach. So why is this happening specifically for the header?

The Reason: Magento’s Header Structure

The issue lies in how Magento structures its default layout XML files. By default, the header reference doesn’t contain a <block type="core/template"> element. Instead, it has child blocks like top links, logo, and other built-in elements.

When you add your custom block using local.xml, Magento isn’t recognizing it because it’s expecting other types of content under the header reference by default.

The Solution: Using Magento’s Core Blocks

To make this work, we need to use one of Magento’s core blocks that already exist inside the header, and then append our custom block as a child.

Here’s how you can do it:

<reference name="top.links">
    <block type="core/template" name="wc-customheadblock" template="wc-customheadblock.phtml" before="-" />
</reference>

In this example, we’re using the top.links reference (which is a child of header) and adding our custom block as its sibling. The before="-" attribute ensures that our block appears at the beginning of the links area.

Testing Your Changes

After making these modifications:

  1. Flush your Magento cache: Run php bin/magento cache:flush in your terminal.
  2. Reload your store’s front page to see if the custom header block has appeared above the top links.

If you’ve followed the steps correctly, your green background box with “This is the wc custom head block” should now be visible!

A Word of Caution

While this solution works for many simple cases, remember that Magento 1.9 doesn’t support layout updates in local.xml by default. For more complex changes or long-term projects, consider using Magento’s Layout XML Generator tool or overriding the core layout files instead.

We’ve written a detailed guide on how to override Magento layouts properly here at Laravel Company. I highly recommend giving it a read for more advanced scenarios.

Conclusion

In this post, we’ve explored why your custom header block wasn’t appearing and provided a practical solution to resolve the issue using Magento’s built-in blocks. Always remember that understanding Magento’s core structure is key to making layout changes effectively.

Happy coding, and don’t forget to check out our Magento development resources for more tips and tricks!

Magento 1 Themes Configuration Errors

Our network