Basic: Run Magento in WordPress

12.Oct.2010

Many developers like combining Magento and WordPress, and there is many more out there that would like to. All snippets showing how to grab data from Magento don’t warn you that there is the function in Magento core that has the same name as WordPress function for translation “__()”. For this reason it is not possible to include Mage.php inside of WordPress.

Copy your functions.php inside of your Magento instalation (../app/code/core/Mage/Core/) to a local folder (../app/code/local/Mage/Core/), and wrap it’s function __() so you get a snippet like this one:

1
2
3
4
5
6
7
if(! (function_exists('__')) )
{
	function __()
	{
		return Mage::app()->getTranslator()->translate(func_get_args());
	}
}

This would prevent function name collision and enable you to include Mage in WordPress. Once you have made a change – you can insert following snippet into your function in functions.php file inside of your WordPress instalation.

1
2
3
4
$mageFilename = realpath('../shop/app/Mage.php');
require_once( $mageFilename );
umask(0);
Mage::app();