4

I want to create the custom header in Magento 1.9. I attached the screenshot of the header like this

enter image description here

I have tried the following code. I have created the static block and static block calling in the header.phtml file

     <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('custom_block_id')->toHtml() ?>

but this code is not working .please suggest me

I have added this original header not working. Menu and logo not displaying.

     <!--- custom header---->    
  <reference name="header">
      <block type="page/header" name="header">
         <action method="setTemplate"><template>page/html/customheader.phtml</template></action> 
     </block>    
 </reference> 
        <!--- original header---->
         <reference name="header">
        <!-- Search box wrapper -->
        <block type="page/html_header" name="search_wrapper" template="page/html/search_wrapper.phtml">
            <action method="insert">
                <block>top.search</block>
            </action>
        </block>

1
  • Did you get any solution ?
    – Pawan
    Commented Aug 7, 2018 at 3:34

2 Answers 2

2
  1. Add the code bellow in : app/design/frontend/{yourpackage}/{yourtheme}/layout/local.xml

    <reference name="header">
        <block type="{block}/{type}" name="custom.header" template="page/html/custom-header.phtml" before="-"/>
    </reference>
    
  2. Create your custom header in : app/design/frontend/{yourpackage}/{yourtheme}/template/page/html/custom-header.phtml

  3. Add <?php echo $this->getChildHtml('custom.header'); ?> in app/design/frontend/{yourpackage}/{yourtheme}/template/page/html/header.phtml

    Info : in <block type="{block}/{type}" if you haven't a custom block for your phtml, please put : <block type="core/template" ...

    before="-" to place it at the top of the header container.

Update:

For a Static block:

in local.xml

<reference name="header">
    <block type="cms/block" name="custom.header">
        <action method="setBlockId"><block_id>block-id-here</block_id></action>
    </block>
</reference>

Then : app/design/frontend/{yourpackage}/{yourtheme}/template/page/html/header.phtml

Add this : <?php echo $this->getChildHtml('custom.header'); ?>

7
  • @pirnce i have created static block then how can write ?
    – pramod24
    Commented Aug 7, 2018 at 12:59
  • Please Look my update
    – PЯINCƎ
    Commented Aug 7, 2018 at 13:05
  • Hi prince i have updated local.xml and custom-header.phtml in above theme folder but it's not working
    – pramod24
    Commented Aug 7, 2018 at 13:24
  • Clean the cache, and check well the id of your custom block <block_id>block-id-here</block_id> block-id-here you replace it by the id of your static block
    – PЯINCƎ
    Commented Aug 7, 2018 at 13:32
  • first i have created custom-header.phtml and In that phtml file added div content and that phtml file called in local.xml file using <block type="core/template"
    – pramod24
    Commented Aug 7, 2018 at 13:37
3

Try to add this code in your xml :

<reference name="header">
    <block type="core/template" name="customheader" template="customheader.phtml"/>
</reference>

And write your custom code in customheader.phtml file.

It may be helpful for you.

1
  • i have added custom header but original header content not working. my menu and logo not display.
    – pramod24
    Commented Aug 7, 2018 at 6:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.