Monday, January 23, 2012

Integrating wordpress and cakephp

In one of my recent project I had a task of integrating Cakephp with Wordpress. The content pages had to be in Wordpress and other dynamic features were coming from CakePHP.

While trying to call Cakephp from wordpress or vice versa I was getting errors like "Fatal error: Cannot redeclare __()". These are mainly because of namespace conflict as Wordpress and Cakephp use some functions with same name.

CakePHP defines its functions in cake/basics.php. When Wordpress is integrated the file wp-includes/l10n.php gets included and has the same function names which results in fatal error.

The alternative is to add:

if ( !function_exists('__') ) :
// the function

for wordpress functions.

But I tried a different work around.
I kept wordpress and app folder of cakephp on root folder. To use same wordpress theme across the website I moved the header and footer.php outside of theme folder and kept in root.
So that the layout of cakephp also calls same header and footer.

Then I changed the .htaccess file to handle wordpress and cakephp related links separately.

This solved the fatal error issue and I was able to use wordpress and cakephp together in my website without any rework.


  1. Thanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write ups thanks once again.

  2. Please, can you give me an example how to do that? Thanks!

  3. i am looking for someone to install WPMU on root alongside my cakephp install... i want user to register and create their own blogs... i have asked a several and they say it cant be done... it sounds like you have done it... your contact form isn't working for me but would like to contact you for more info... ltz

  4. You can fill in your name, email id and the detail (as all fields are required) in the contact form.

    To run both wordpress and cakephp, the wordpress files also needs to be on the root folder as well as cakephp app folder.

    So your folder structure should be: