WordPress and Magento integration extension

Wordpress Deluxe

Try WordPress Deluxe for a fully integrated solution for Magento CE and EE

You can now obtain a copy of the Magento WordPress Deluxe Extension. Our store isn’t live yet, so we are taking orders via email at the moment.

The price is £100 including free installation (theming is not included).

Buy WordPress Deluxe now!



Otherwise, here’s the old free version

We’re not trying to re-invent the wheel here, nor are we going into any depth of connecting the authentication modules. From a front-end standpoint, the two “elements” wordpress and magento are essentially one – but all administration is carried out via either separate admin. With this extension, it is easy to facilitate your magento wordpress integration.

Where our solution works better than the others (Lazzymonks or ActiveCodeline), it actually allows the clean search engine optimised URL’s from WordPress to be used in Magento’s breadcrumbs and address bar. It also takes advantage of Magento’s standard caching functionality, so the speed is very impressive. We also integrated the “Pages” listing in the sidebar with that of the Magento CMS, so you can use WordPress for posts and still retain the Magento CMS for pages.

Combining Magento and WordPress provides a big thumbs up for SEO, ease of use and performance.

So why use the WordPress Magento extension?

  • Includes breadcrumbs
  • Supports SEO Urls
  • Supports META tags
  • It is free! (we can also install it for you for a small fee)
  • It comes with a feed widget for both comments and posts *new
  • Now integrates Magento user’s profile for posting comments *new

Installation

Installation might not be that straightforward as we developed it purely for a quick and clever wordpress / magento intergration, so we’ll try to explain as best we can!

This was tested and used with WordPress 2.8 with Magento 1.3.2.4 and WordPress 2.8 with Magento 1.4.0.0 at the time of writing

Current version: 1.2.1

  • 1

    First, download the files that you need
    Sonassi_Wordpress_Module.tar.gz
    Sonassi_Wordpress_Theme.tar.gz
    Sonassi_Wordpress_MagentoTheme.tar.gz
    WordPress.xml.tgz
    Generate_htaccess.tar.gz
  • 2

    Make a new directory ./app/code/local/Sonassi then install the Sonassi_Wordpress_Module.tar.gz by extracting the tar file, then put the directory “WordPress” in to a new folder ./app/code/local/Sonassi.
  • 3

    Download and install the latest version of WordPress from http://wordpress.org/latest.zip. Extract to ./blog (you can also change this, but you will need to change the blog reference throughout) and install WordPress as normal.
  • 4

    Extract Sonassi_Wordpress_Theme.tar.gz into the ./blog/wp-content/themes directory and select the Magento WordPress 1.0 by Sonassi as the active theme.

    In Settings > Permalinks set custom structure with /%category%/%year%/%monthnum%/%postname%/ for SEO.
  • 5

    As people seem to be having difficulty identifying their server’s outbound IP address – we have put together a script to automatically create both .htaccess files – or amend as necessary. Download Generate_htaccess.tar.gz into your WordPress directory (/blog), then visit your website http://www.example.com/blog/generate_htaccess.php. This should automatically perform steps 5 and 6 for you.

    Edit ./blog/.htaccess and add the following information at the start, replace the XXX section with the outbound IP address of your server. This is to prevent the un-styled raw pages from WordPress ever being displayed or indexed.

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /blog/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !^/blog/wp-admin
    RewriteCond %{REQUEST_URI} !^/blog/wp-content
    RewriteCond %{REQUEST_URI} ^/blog
    RewriteCond %{REMOTE_ADDR} !^XXX.XXX.XXX.XXX
    RewriteRule .* ../index.php [L]
    </IfModule>
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L]
    </IfModule>
    # END WordPress
      
  • 6

    Update your ./htaccess to allow WordPress to work, add this just beneath RewriteBase /

    ############################################
    ## sonassi.com wordpress extension
    ##
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_URI} !^/blog/wp-admin
        RewriteCond %{REQUEST_URI} !^/blog/wp-content
        RewriteCond %{REQUEST_URI} ^/blog
        RewriteCond %{REMOTE_ADDR} !^XXX.XXX.XXX.XXX
        RewriteRule .* index.php [L]
      
  • 7

    Extract Sonassi_Wordpress_MagentoTheme.tar.gz to ./app/design/frontend/default/default/template . We deliberately left these files almost empty – so you can customise them to your needs.

    Extract WordPress.xml.tgz to ./app/design/frontend/default/default/layout. This file contains the XML for the extension, it has a default handle of blog_default that is applied to every page, this can be adjusted to suit your desired look.

  • 8

    Create a new file ./app/etc/modules/Sonassi_All.xml to enable the WordPress module

    <config>
      <modules>
        <Sonassi_Wordpress>
          <active>true</active>
          <codePool>local</codePool>
        </Sonassi_Wordpress>
      </modules>
    </config>
    


That should be it, add some example posts, then visit your news on the front end via www.YOURDOMAIN.com/blog/ . We must stress that this Magento wordpress extension was never designed for mass installation – it was a quick one off for a customer that turned out to rival (if not better) the alternatives out there.

We’ve set up an example at http://demo.sonassi.com/blog/ – from following the directions above, we haven’t themed any element of it so you can see how it will look from the onset.

What’s going on, I keep getting redirected to the 404 page

*This only applies to version 1.1 or lower

On around line 163 of ./app/code/local/Sonassi/Wordpress/Page.php, there is a call to grab the current store code. We liberally assumed that “default” would be your default store name, if it isn’t, then it will cause 404 redirect errors.

Simply change it to,

$store = Mage::app()->getStore()->getCode();

allow_url_fopen is disabled

In this case, you will need to replace the function getPage() in Model/Page.php with the cURL alternative.

    public function getPage()
    {
      $url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB).$_SERVER['REQUEST_URI'];
      $url = str_replace("//blog","/blog",$url);
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_FAILONERROR, true);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
      curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
      curl_setopt($ch, CURLOPT_MAXCONNECTS, 20);
      curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
      curl_setopt($ch, CURLOPT_TIMEOUT, 5);
      $content_curl = curl_exec($ch);
      $response_curl = curl_getinfo($ch);
      curl_close ($ch);
      if ($response_curl['header_size']) {
          $type = $response_curl['content_type'];
          if ((strpos($type,"text/html") === false && strpos($type,"application/x-httpd-php") === false)
                 || strpos($type,"text/xml") !== false ) {
            if ($ch && $content_curl) {
              foreach ($response_curl as $header => $key) {
                header($header.":".$key);
              }
              echo $content_curl;
              exit();
            } else if ( strpos($type,"text/xml") !== false ) {
              echo $content_curl;
              exit();
            } else {
              header("Location: /no-route");
              exit();
            }
          }
          $this->buffer = $content_curl;
          return $this->buffer;
      } else {
        header("Location: /blog/");
        exit();
      }
    }

I’m stuck in a redirect loop

This is caused by either two things, incorrect request URL or the content-type being mis-read. Edit Model/Page.php and add the following lines instead:

   $url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB).$_SERVER['REQUEST_URI'];
+ $url = str_replace("//blog","/blog",$url);
 //$type = end($http_response_header);
 $type = false;
 foreach ($http_response_header as $headerVal){
   if(stristr($headerVal, 'Content-Type') !== false)
   $type = $headerVal;
}

But I want to change the URL

That can easily be done by changing the following files:

In .htaccess change all blog > news.
In blog/.htaccess change all blog > news.
In app/code/local/Sonassi/Wordpress/etc/config.xml change blog > news.
In app/code/local/Sonassi/wordpress/Model/Page.php change blog > news.
In blog/wp-config.php, add

define('WP_HOME','http://example.com/news');
define('WP_SITEURL','http://example.com/news');

I’d also like to incorporate the WordPress feeds on my site!

Then you should read our guide on WordPress feed integration for Magento.

 

 

  • http://www.amit-joshi.com Amit Joshi

    Hi there,
    I Installed magento 1.4.x
    followed instructions above
    added few products but the blog link is not appearing in the menu bar
    also if I type http://127.0.0.1/www/project/blog/

    the page which appears is losing stylesheet

    can u please guide me where I am mistaken..

    thanks in advance

    Regards

    Amit Joshi

  • Michael

    This is exactly what i have been looking for but its not working for me, as such.

    I am using it on a localhost with MAMP, WP.3.0 & Magento 1.4.1.0, following all the instructions, see that the .htaccess has been generated but when I goto http://localhost/blog it DOES bring the Magento home page but with a “404 Not Found 1″ error.

    I did notice however when using the generate_htaccess.php it did come up with some error. Here is one which I have just done buy deleting the .htaccess file with i the blog directory.

    Warning: file_get_contents(.htaccess) [function.file-get-contents]: failed to open stream: No such file or directory in /Users/Michael/Sites/blog/generate_htaccess.php on line 16
    .htaccess generatedMissing sonassi_wordpress code in .htaccess
    .htaccess generated

    It would be great if anyone has had the same problem and has found a solution

    Thanks
    Michael

  • Jon

    I’m running xampp on Win 7 64bit, and have the same issue as a lot of people here… although i don’t think this is OS related.
    I do think it is all about the IP address. I’m not sure how this works in a production environment but locally I’ve got the site hosted with the 127.0.0.1 IP, When I run the generate_htaccess.php script it changes the local IP to the IP assigned by my ISP which effectively resolves to my router and ends there.
    It’s my hunch this is where the problem lies since the script is setting an IP address that is not accessible it’s never going to resolve. Am I correct?

    If so this could mean for those having issues in a production environment (shared IP hosting), their DNS settings could be affecting the ability to use this feature?

    That kinda makes me wonder too if the XAMPP default site is interfering with resolving the address.

    Anyway, that’s where I’m at after 3 days of rebuilding xampp, mage, wp several times to no avail.

    I’m wondering also if this integration is viable in enterprise edition? I’m setting up a store that is most likely going to be need enterprise edition to link POS/Back Office tools so is this even worth spinning my wheels?

    Thanks for any replies!

  • Jon

    Also, when I change the IP in root htaccess to 127\.0\.0\.1 it pulls up the WP with just the blank theme (which is what this feature is trying to avoid I thought). Interestingly though if I change it to any other IP it goes into the loop just like with the outfacing IP set by the generate_htaccess.

    Am I supposed to create a page in Magento called blog and add static block or something? Or do I just add a link to mydomain.com/blog?

    Sorry for being another headache on the list of troubled users. I believe I have followed the instructions to the letter. Maybe there’s something fundamentally missing in my setup and obviously that is not within the scope of your posting, but even coming from the .net side of things, I understand the structure and logic behind what’s being explained here.

    If it matters:
    My vhost file is pointing to my site as the default site and the named site, created a new ssl in openssl for the domain, all seems pretty straightforward, but I’m still all loopy.

    Happy Canada Day eh!

  • Tee

    Does this extension work with Magento version 1.4.1.0 and WordPress version 3.0?

  • Tee

    Hi, I’ve installed your extension with wordpress 3.0 but when I browse to mysite/magento/blog/ I have a blank theme and I’ve tried following the instructions several times, still no luck. Magneto is installed in a sub domain, does that make any difference to the outcome?

    Any help would be really appreciated.

  • Pingback: boogles » Blog Archive » Wordpress and Magento Integration

  • http://www.mk2dev.com Dylan

    I was having a similar redirect loop that others have mentioned and only in a live environment (development and staging servers worked flawlessly).

    After ensuring several times that my IP address was correct, I found my issue.

    In line 85 of ./app/code/local/Sonassi/Wordpress/Model/Page.php is the following line:
    $type = end($http_response_header);
    Content-Type is not guaranteed to be in the last position.
    I replaced this with the following:
    $type = false;
    foreach ($http_response_header as $headerVal){
    if(stristr($headerVal, 'Content-Type') !== false) {
    $type = $headerVal;
    }
    }

    and everything seems to be working great.

    Also of note, make sure that you have allow-url-fopen set to true in your php config, as this solution won’t work without it.

    btw guys, clever solution to integrating wordpress! Aside from some minor launch issues seems to work wonderfully!
    Thanks!
    -d.

  • kidalynch

    So if I would like to use this with the enterprise edition of magento my theme paths are not

    ./app/design/frontend/default/default/layout

    but
    ./app/design/frontend/enterprise/default/layout

    Will this be an issue if I put them in my enterprise/default path?
    Or will i need to modify that path somewhere?

    Thanks!

  • http://www.hampshirebaits.co.uk John Boswell

    Hi Ben, how do we add some better styling to the blog, like you have with the nice calendar dates, I also want to remove the left column and just have a right column with blog categories, archive, links etc.

    Hope you can please help

    Regards

    John

  • http://www.hampshirebaits.co.uk John Boswell

    Hi Ben, I have managed to fix the design issues, still playing around, but got it sussed.

    One issue is with facebook like button, I need to add the following code between the tags. (already done on main magento site as facebook like buttons are working fine on product page, but not working on blog, so need to find where blog head tags comes from)

    Hope you can please help so I can enable xfbml method which enables users to post a comment on what they like.

    Thanks

    John

  • Style broken

    Hello, Ben

    this is great extension.

    I installed it on my site, I used Magento 1.4.0.1 and WordPress 2.9.2.

    your extension is working on these versions?

    Regards,

  • Tico

    Same here, double page 404 error. Anybody found out how to fix this?

  • Tico

    Hello Ben,

    First, thank you for providing this extention to the community.

    I installed it several times with different versions of Magento and WordPress. Unfortunately, I cannot get it to work.

    I have a double-page 404 error.

    I checked the intructions, htacess files were generated via php generator file provided here and I checked them to make sure they were as stated above. All is well, except it is not working.

    Can you shed a light in might seem to be the problem and how could i fix it?

    thanks

    Magento 1.3.2.4
    Wordpress 3.0

  • Andy

    Hi Ben

    I do have this problem as well for 2 implementations I’m using your plugin with. Besides that everything works great. Any idea on how to fix this?

    Thanks a lot for your great work!
    Best,
    Andy

  • http://www.blackwellprint.co.uk Tom Davison

    Hi there,

    I’ve got this integration working fantastically with Magento 1.4, the only minor issue is the breadcrumb, it’s a bit untidy and reads like this when in a post:

    Home / Blog / Printing-leaflets-flyers-business-cards-folders / 2010 / 07 / Exhibitors-specials

    It’s technically correct but looks a bit iffy and dodgy. Is there a way of correcting this? I’ve tried ALL the breadcrumbs suggestions in this thread/reply section and all I get is parse errors. I’m pretty experienced in Magento but can’t quite suss this one.

    Any suggestions appreciated.

    Cheers

  • http://www.sonassi.com ben@sonassi.com

    Hi Tom,

    You could just change the permalink format to something else, perhaps

    /%category%/%postname%/

  • http://www.sonassi.com ben@sonassi.com

    Hi Tico,

    This is a common bug, the URL in Page.php is malformed – it probably contains “//blog”, add a:

    $url = str_replace("//blog","/blog",$url);

    Under the $url declaration.

  • http://www.sonassi.com ben@sonassi.com

    Hi,

    It certainly does. It is compatible with Magento 1.3, 1.4 and WordPress 2.8 > 3.0

  • http://www.sonassi.com ben@sonassi.com

    Hi John,

    The blog header is defined in header.php :)

  • http://www.sonassi.com ben@sonassi.com

    Hi John,

    We certainly could – best get in touch!

  • http://www.sonassi.com ben@sonassi.com

    Hi,

    It shouldn’t be an issue, the paths are inherited from the theme you have defined for the store view.

  • http://www.sonassi.com ben@sonassi.com

    Hi Dylan,

    We have seen this issue before. It was to be fixed in the next release, but the extension has now been superseded by our deluxe edition – which removes the file_get_contents/curl calls altogether.

  • http://www.sonassi.com ben@sonassi.com

    Hi Tee,

    This isn’t an issue with WordPress v3.0 – it is because Magento is not controlling the rewrite. I would suggest following the instructions again, or trying the deluxe edition.

  • http://www.sonassi.com ben@sonassi.com

    Hi Tee,

    Yes it does!

  • http://www.sonassi.com ben@sonassi.com

    Hi Jon,

    It could be a number of things, throw a few exits around in Page.php on the $url,$type to see what has been declared.

    And Happy Canada day to you too ;)

  • http://www.sonassi.com ben@sonassi.com

    Hi Jon,

    It outright will not work on a localhost server because the server IP is the same as the request IP. Unless you change the listening interface of Apache – it will always fail to work.

    You could try the deluxe edition which now bypasses all known issues.

  • http://www.sonassi.com ben@sonassi.com

    Hi Michael,

    It outright will not work on a localhost server because the server IP is the same as the request IP. Unless you change the listening interface of Apache – it will always fail to work.

    You could try the deluxe edition which now bypasses all known issues.

  • http://www.sonassi.com ben@sonassi.com

    Hi Amit,

    It outright will not work on a localhost server because the server IP is the same as the request IP. Unless you change the listening interface of Apache – it will always fail to work.

    You could try the deluxe edition which now bypasses all known issues.

  • http://www.sonassi.com ben@sonassi.com

    Hi Peter,

    This is a nasty side effect of this extension. It was admittedly thrown together in haste, we have replaced it with the deluxe edition of the extension because of the overheads outlined above.