Integrating Magento Header/Footer in WordPress – Solved

  • 13 May , 2015
  • by
Magento Wordpress

Blogs are of paramount importance to a website and especially to a Magento Developed Online Store. Blogs bring forth traffic and are the prime source of SEO leads. In this tight race of Blogging Platforms, WordPress has turned out to be the fastest horse in the derby.

WordPress is the best platform to showcase Blogs and Case Studies. Now if you wish to combine the superiority of WordPress with a Magento Store then this article is the perfect solution to your problems.

Integrating Magento Header Footer in WordPress - Solved

Here we will talk in details how to integrate your Magento Header & Footer in a WordPress site.
We are considering WordPress code is within a folder named “blog” inside the Magento project.


$str = dirname(__FILE__);
$basedir = substr($str, 0, strpos($str, 'blog'));
$mage_php_url = $basedir . 'app/Mage.php';

// Include Magento application

if (!empty($mage_php_url) && file_exists($mage_php_url) && !is_dir($mage_php_url)) {
// Include Magento's Mage.php file
require_once ( $mage_php_url );

After this you can use the Magento code in your WordPress code.

$url = Mage::getBaseUrl();
 $url = substr($url, 0, strpos($url, 'index.php'));
 // skin url of magento
 $skinUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);
 //js url 
 $jsUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);

This will provide you with the Magento url, Skin url and js url.

Include Magento session so that customer and checkout session will be maintained in it.

Mage::getSingleton('core/session', array('name'=>'frontend'));

After inserting this line if the user is logged into Magento then it will show him/her as logged into WordPress as well. Cart header will show updated cart items as well.

Now let’s include time the js and css files. Include all js and css files of Magento to get the style and functionality of Magento.

<link rel="stylesheet" type="text/css" href="<?php echo $skinUrl . 'frontend/default/default/css/styles.css'?>" media="all" />
<script type="text/javascript" src="<?php echo $jsUrl .'prototype/prototype.js'?>"></script>

In similar ways, you can include other files as well.

The Header

$_layout = Mage::getSingleton('core/layout');
$block_header = $_layout->createBlock('page/html_header')-

This will include header.phtm files.

Top Menu

$block_Menu = $_layout->createBlock('page/html_topmenu', 'catalog.topnav')-
$block_header->setChild('topMenu', $block_Menu);

Likewise include the other needed block

Top Links

$block_links = $_layout->createBlock('page/template_links', 'top.links')->setTemplate('page/template/links.phtml');
$block_header->setChild('topLinks', $block_links);
$block_links->addLink('Home', $url . '', 'Home','', '', 10,'', 'class="top-link-home"');
$block_links->addLink('Account', $url . 'customer/account/', 'Account', '', '', 10,'','class="top-link-account"');
$block_links->addLink('Shopping Cart', $url . 'checkout/cart/', 'Shopping Cart', '', '', 10,'','class="top-link-cart"');
$block_links->addLink('Checkout', $url . 'checkout/onepage/', 'Checkout', '', '', 10,'','class="top-link-checkout"');

It will include Home, Account, Cart and Checkout link on the header. Other links can be added similarly.

echo $block_header->toHtml();

This will show the header html.


 $layout = Mage::getSingleton('core/layout');
$footerBlock = $layout->createBlock('page/html_footer')->setTemplate('page/html/footer.phtml');
$news_subscribe = $layout->createBlock('newsletter/subscribe')->setTemplate('newsletter/subscribe.phtml');
$footerBlock->setChild('newsletter', $news_subscribe);
echo $footerBlock->toHtml();

This will include footer.phtml file and it will be called ‘Newsletter’ inside the footer.

I can say with a good amount of certainty that this article will help you in including Magento styles in your WordPress site.

Happy Coding

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Want us to develop your Mobile/Web Solution?