What is the best strategy to integrate WordPress inside of Magento?

I've used the Fishpig module on a load of sites, have bought the paid for plugins and have been happily promoting it for years. However, I am not using it any more. It does what it does well, but what it does is run everything through Magento.

Let's face it, the client takes one look at a Wordpress site and suddenly starts getting creative. 'We can do this in Wordpress!', 'We can do that in the Wordpress install!'. You have to keep explaining to them that normally, yes that is easy to do in Wordpress....but that their Wordpress installation isn't normal as it is all running through the Magento itself and that changes everything.

So your bank of custom Wordpress widgets won't work, 3rd party Wordpress plugins won't work. Themes and theme options won't work. Unless you do a load of work converting and assimilating them into the Fishpig module.

A much better approach in my opinion is to go the way of James Kemp (http://wordpress.org/plugins/magento-wordpress-integration/) or Richard Feraro (http://wordpress.org/plugins/mage-enabler/). They both take the same approach, allowing you to access the Mage object from Wordpress and pull whatever you want from Magento into your Wordpress theme. If you look at the plugins though, they are very simple and don't involve much code.

They both require a modification to app/code/local/Mage/Core/functions.php as both Wordpress and Magento have a function __() method declared. There are detailed notes about it on both plugin authors sites though and it is very easy. After that you can get stuck in.

It's so simple, here's an example using the James Kemp plugin. You can have a stripped down Wordpress theme with a header.php like;

<!DOCTYPE html>
<html class="no-js">
<head>
    <?php the_block("head"); ?>
    <?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>

Which pulls your whole Magento head block into the Wordpress header. Perfect, no duplication, no additional work. Note I added wp_head() because if you add in Wordpress plugins they'll potentially use that as a hook and it's good practice to have that in your Wordpress header.php file.

Same goes for footer.php;

    <?php the_block("footer"); ?>
    <?php wp_footer(); ?>

  </body>
</html>

And there's your Magento footer block in Wordpress. The rest is up to you but you've got the freedom to add as much additional stuff into your Wordpress install as you like without any constraints.

Edit - May 14

Since I wrote this I've also started using Wordpress as the CMS and pulling data back into Magento using this Wordpress plugin - JSON API plugin http://wordpress.org/plugins/json-api/

To give you a code example - the code below pulls the requisite entries in Wordpress for a custom post type called event, accesses a custom field in those posts called eventdate puts them all in an array, sorts it by date and outputs a list of all the events with a link to each event page in Wordpress install. I've used it in the main navigation of a Magento site in a dropdown, it works really well. Wordpress is due to have a JSON API added to the core but as of yet it's not been released.

<ul>
    <?php 

    $events = json_decode(file_get_contents('http://www.example.com/blog/?json=get_posts&post_type=event'));

    $eventList = array();

    foreach ( $events->posts as $event_item ) :

        $arrayDate = date("ymdHi", strtotime($event_item->custom_fields->eventdate[0] ));

        $eventList[$arrayDate]['Title'] = $event_item->title;
        $eventList[$arrayDate]['Date'] = date('l jS F', strtotime($event_item->custom_fields->eventdate[0] ));
        $eventList[$arrayDate]['Link'] = $event_item->url;


    endforeach; 

    // Key reverse sort to get events in date order
    ksort($eventList);

    foreach ($eventList as $eventItem) : 

        echo '<li><a href="'. $eventItem['Link'] .'">'. $eventItem['Title'] .' - '. $eventItem['Date'] .'</a></li>';

    endforeach;     

    ?>
</ul>

Edit - Oct 15

I recently had to try and use this integration method in a multi store that was using the same country code subdirectories as in this question by Matthias Zeis;

Different storeviews or websites in subfolders

I did consider trying the Fishpig multistore extension for this but in the end I asked a question on SO -> https://stackoverflow.com/questions/32613815/htaccess-wordpress-under-magento-site-with-multi-language-sub-directories

I've put the answer up there, it uses server environment variables and some Wordpress filters. I've added the .htaccess and Nginx server blocks too to help.

Also, for anyone who deploys their Magento site using Capistrano and shivers at the prospect of having the constantly updated Wordpress core and plugins polluting their repo I wrote a blog post showing how you can just move the whole lot into the shared directory in Capistrano 3 and only have your Wordpress theme in the repo;

http://www.mcnab.co/blog/wordpress-git-and-capistrano-v3/


It depends. You've choice :

  • Use a dedicated module like the Fishpig's module http://www.magentocommerce.com/magento-connect/wordpress-integration.html
  • Use JSONP to purpose to load the header and footer

If you use the Fishpig module (which is a good module) you can use http://www.magentocommerce.com/magento-connect/mage-wordpress-integrated-search-4394.html

The latest solution is to develop your own WordPress integration on Magento :)


Fishpig's WordPress integration extension. It's free, works well, integrates the theme. Doesn't integrate the search. But it's the best integration method we're aware of.