How to use WordPress home page in Magento home page (CMS page)

How to use WordPress home page in Magento home page (CMS page)

Simple : ) -Ok, lets get down to business. This one is really, really simple, but powerful. In all it greatness Magento lacks the good content management solution (CMS features). Lot of people are heading down the road of integrating the WordPress and Magento. Probably everyone in web development has heard about WordPress. Personaly I like them, from Joomla, Drupal, WordPress… But there is that little something that makes WordPress far more loving in the eyes of the client. Not to start a flame here, lets get back to the topic. Due to the lack of the proper content management in Magento those who use WordPress can easily manage the (home page in this case) content trough WordPress and make it accessible in Magento CMS page (that you can set to home page in Magento).

When would you like to do so?

Imagine you have Magento installed in root of your site and WordPress under some folder like /articles. By default WordPress is accessed via http://mysite.domain/articles and Magento is accessed trough http://mysite.domain. Our goal is to have WordPress Page (that we will title “home“) to be accessible on http://mysite.domain.

Here are the necessary steps involved:

  • Create a WordPress page named “home” (under url like http://mysite.domain/articles/wp-content)
  • Create a file named cmswp_home.phtml under app/design/frontend/default/yourtheme_or_default_theme/template/inchoo/ folder
  • Create a Magento CMS page (if it already does not exist) name it anyway you want and then add {{block type=”core/template” template=”inchoo/cmswp_home.phtml”}}
    to its content
  • Set the newly created Magento CMS page as home page for Magento under Magento Admin System > Configuration > Web > Default Pages > CMS Home Page

Below is the code you need to copy paste into the cmswp_home.phtml file mentioned in above steps.

< ?php
* Pulls the content of post named 'home' from WordPress 'wp_posts' table
* @author Branko Ajzele
* @license GPL
//Fetch database connection
$_conn = Mage::getSingleton('core/resource')->getConnection('core_write');
//Set query that retrieves the home page content
$_findHomePage = "SELECT post_content FROM wp_posts WHERE post_name = 'home' AND post_status = 'publish' AND post_type = 'page'";
//Set default value of home page to null, then do a safe check just to be more user friendly
$_homePageContent = null;
try {
$conf = array(
'host' => 'localhost',
'username' => 'wordpress_db_username',
'password' => 'wordpress_db_password',
'dbname' => 'wordpress_db_name'
$_resource = Mage::getSingleton('core/resource');
//Create new connection to new server and new databse
$_conn = $_resource->createConnection('place_some_free_random_resource_name_here', 'pdo_mysql', $conf);
$_homePageContent = $_conn->fetchOne($_findHomePage);
catch (Exception $ex) {
* USE $emailSmtpConf, $transport and $mail->send($transport); in case you need to specify SMTP manualy
$emailSmtpConf = array(
'auth' => 'login',
'ssl' => 'tls',
'username' => '',
'password' => 'some_pass_here'
$transport = new Zend_Mail_Transport_Smtp('', $emailSmtpConf);
$_sendTo_email = '';
$_sendFrom_email = '';
//Notify each item author about purchase
$mail = new Zend_Mail();
$mail->addTo($_sendTo_email, 'Branko Ajzele');
$mail->setFrom($_sendFrom_email, 'Branko Ajzele');
$mail->setSubject('Invalid HOME PAGE on site detected');
<h1>Invalid HOME PAGE on site detected</h1>
<p>There seem to be some issues with home page on your site. Please take a look at it.</p>
<p>Could be that WordPress page has been disabled and this made the query for page return null.</p>
try {
//Try to send email
catch (Exception $ex) {
//echo $ex->getMessage();
< ?php if($_homePageContent): ?>
< ?php echo $_homePageContent ?>
< ?php else: ?>
<h1>Home page unavailable</h1>
<p>Seems like home page is unavailable at the moment. We apologize for the inconvenience.</p>
< ?php endif; ?>

That’s it.

If you wish to have more control over what is outputted take a look $_findHomePage variable and the query behind it.

Hope you find this useful.


You made it all the way down here so you must have enjoyed this post! You may also like: revamp Zeljko Prsa
Zeljko Prsa, | 10 revamp

How much do you really blog on your Magento shop? Branko Ajzele
Branko Ajzele, | 52

How much do you really blog on your Magento shop?

Where are my geocoins? Landsharkz is launched! Tomislav Bilic
, | 1

Where are my geocoins? Landsharkz is launched!


  1. Hi Branko Ajzele
    At first take my sincere respect. I have gone through your article. I think if you write about some good theme for WordPress it will very helpful for us.
    Moreover i like your full article and it is very helpful for me.
    Looking forward to hear from you soon.

    Thanks sincerely

  2. Hi, great technical stuff, but to me, it’s not a godd idea in a seo purpose. Cause the wordpress home won’t be optimized to send page rank between her links. If you have a blog and an e-commerce on the same url it’s probably to sell more than to display content, so i suggest to keep magento’s home page and display the blog in a subfolder eshopmagento.tld/blog
    Since i rcently lauched my company as seo e-commerce ( i’m starting to change my point of view on some technical stuff. Those must be think with the big picture and not only as “a wordpress or magento homepage?” discussion.

  3. Hi, I just found your article about having a WordPress page displayed for a Magento store.
    I’ve got to implement this on a live site, so I’ve got a question about the php code.

    In the code you’ve provided, are most of the features redundant, do I need to delete (or comment out) the lines for email, server/database connection if my Magento is installed in root and WP is in a /wordpress folder on the same root?

    I’m using WP v 4.1 and Magento CE v 1.7

    Thanks for posting such a useful article.

  4. Hi All ,

    I have wordpress and Magento installed in two different servers . I need to use wp header and wp footer in Magento Fish pig module.

    Can somebody help me in that ?

  5. The fishpig extension has this feature built in now so you can get the wordpress blog listing or page as the magento homepage easily

  6. What do I use in place of
    on line 32?

    My magento and wordpress are on the same server but different databases. Do I comment out line 14? Should I uncomment lines 22-32?

  7. I have found that this implementation has one enormous problem. Auto generated content does not show header or footer. Hopefully this saves someone a lot of time.

  8. Could someone possibly expand on:
    1) How to add the entire pages content less header and footer rather than just pulling the posts
    2) What I change within the file to have it pull a different wp page? I am not using it for the home page, but am for the about us, faqs, etc.

    Sorry for the lack of knowledge. I actually got it to do exactly what it is designed to though. 🙂

  9. Hi Branko

    This is really cool 🙂 Thanks so much for sharing.

    I’ve got two questions if I may :

    1) Do you know if the content that is pulled back is CACHED in any way?

    2) I’m wanting to use this to pull back ANY page from WordPress – so pass in a parameter somehow (perhaps the page name or some such) – do you know if this would be easy to do?

    Thanks in advance 🙂


  10. Can something like this be used with Xsitepro? What would be required to get this integration. Creating a template in Xsitepro and overlaying Magneto??? Could this work?

  11. i’m using lazzymonks wordpress extension on my magento shop.
    i’d love to open wordpress page instead cms pages. i’ve tried this howto but it’s not workin’…
    nothing happens.

  12. busy with day job and paying Magento gigs so no documentation yet but see
    prototype pulls in wordpress content and it’s styled with Magento css.
    all pages with the footer
    “westgardiner.netContent is proudly powered by WordPress”
    are wordpress posts. Just add Postie WordPress mod and you can email content directly to Magento.
    of course it’s a work in progress…

    fyi inchoo, activecodeline and snippi are the best for Magento info hands down…


  13. I have had the same problem. I never thought of doing the home page this way. I have some other ideas, but they do require manual coding. Using wordpress would be perfect for that.

    There was a wordpress integration module for magento, but its not working for me.

    I have thought of reversing it and building a plugin to integrate Magento directly into WordPress.

  14. @LekeFly, @Rosco

    I am not sure what you mean by demo here? Not much you would see. Imagine a WordPress page with custom content. Now imagine you take that content (which is actually a HTML string) and output it inside the Magento block.

    Its like imagining the content of these commecnt being pulled inside one of the Magento blocks.

    I was merely trying to show a concept, a possible way of using things.

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=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.

Tell us about your project

Drop us a line. We'd love to know more about your project.