Sometimes nerdy and wordy, but mostly helpful articles on website design and development.

Magento and WordPress together – an updated approach

| 8 Comments | Magento, WordPress

A few year ago, I wrote a post on Magento and WordPress go together like Chocolate and Peanut Butter and it’s been one of my top posts. So, I thought I’d write again about the two great platforms and how I approach them as the previous post is a little out-dated.

I still love Chocolate and Peanut Butter 🙂 but my approach to combining WordPress’s powerful CMS/blogging platform with Magento’s robust eCommerce platform has slightly changed.

The super fast approach – NOT recommended

The fastest way to get Magento and WordPress working together is to use the Magento extension FishPig. As a developer, I can’t recommend this approach as it really limits what you can do on your WordPress blog. You can’t install and use any WordPress plugins that are not supported by FishPig. For this major reason, it’s one I never use.

My Go-To Approach

I have been installing WordPress in the root directory of the website and installing Magento in a sub-folder. You can of course, do it the other way around, but it’s just much easier from a developer’s standpoint to create landing pages, add forms from WordPress and have a cleaner URL.

I had been using the Mage Enabler plugin, but a couple of years ago, started using James Kemp’s Magento WordPress Integration plugin exclusively as it works much better with how I do things. Follow these simple steps below to get your WordPress and Magneto themes working in tandem using the MWI plugin.

Step 1: Deactivate the __() function in Magento

Step 1, is not to install a plugin, we need to prep our environment first. To do this we copy ‘~/your-magento/app/code/core/Mage/Core/functions.php’ into ‘~/your-magento/app/code/local/Mage/Core/functions.php’ and find code for the function __() (around line 90)

function __() { return Mage::app()->getTranslator()->translate(func_get_args()); }

We will replace that code with the following

if(!function_exists('__')) { function __() { return Mage::app()->getTranslator()->translate(func_get_args()); } }

Step 2: Install the Magento WordPress Integration Plugin

You can install from the plugins area of WordPress or manually upload via FTP.

Step 3: Configure the Magento WordPress Integration Plugin

In WordPress, navigate to Settings > Mage/WP and fill in the full path to Magento’s mage.php file. If you have a custom Package and Theme, you’ll set it here as well.

Step 4: Eat some Chocolate covered Peanut Butter to Celebrate

Ok, this isn’t a real step, but I told you I love these two 🙂

Using WordPress Functions and ShortCodes in Magento

Now that we have the ability to put Magento content anywhere in our WordPress site, it would be nice to do the same in Magento, right? Easy enough. We need to include the ‘wp-blog-header.php’ file to load the WordPress environment and header.

Go to your Magento root folder and open your index.php file. In it, we’ll add 1 line of code (and a 1 line comment).

/** Loads the WordPress Environment and Template */
require( '../wp-blog-header.php' );

From here, we can use any custom functions we have in our functions.php file or whatever you’d like. Some things that I use in Magento from WordPress are:

  • Add the WordPress menu to the Magento header
  • Add the WordPress footer to Magento footer
  • Call custom functions, shortcodes and settings stored in WordPress

If you’ve found this post to be helpful, please share it with your twitter followers and let me know if you’ve implemented with success.

8 responses to “Magento and WordPress together – an updated approach

  1. You said: “copy ‘~/your-magento/app/code/core/Mage/Core/functions.php’ into ‘~/your-magento/app/code/local/Mage/Core/functions.php’” but I don’t have a ‘local’ folder under ‘app/code’ – should I be creating this folder?

    1. Yes. The local folder under app is used to override the core functionality. So what you’re doing here is telling Magento to pull functions.php from local as you have modified it.

  2. If I will install magento in sub-dir, it will add sub-dir name in magento product urls and custom modules, is there a way to eliminate it?

  3. I already have a Magento site installed with a theme. I want a WordPress installation to take on the Magento’s theme, eg. the fonts, header, footer and menu. Do your steps address that? If not, how should I go about it?

  4. Lovely. Would just like to add that

    /** Loads the WordPress Environment and Template */
    require( ‘../wp-blog-header.php’ );

    or any instantiation in the Magento index.php file needs to happen first or else you will stare at your screen like a 4 year old watching Barney for a half hour.

Comments are closed.

Get the Latest

  • Get email updates whenever we post new blog articles.
  • This field is for validation purposes and should be left unchanged.

Recent Articles