Question

How to integrate WordPress template with CodeIgniter

How can CodeIgniter and WordPress be integrated such that the look and feel/template of the WordPress blog is carried over to the CodeIgniter-created pages?

 45  24804  45
1 Jan 1970

Solution

 33

First step is to move CodeIgniter and the WordPress files in their own directory.

After that, put the following line at the top of your CodeIgniter's index.php file. Change the path to wp-blog-header.php as needed to point to your WordPress's root directory.

<?php
    require('../wp-blog-header.php');

Then, you can use the following functions inside your views:

<?php
    get_header();
    get_sidebar();
    get_footer();    
?>

Other helper functions can also be found in WordPress's documentation which can assist you in integrating the design.

2009-08-10

Solution

 16

When I included the file wp-blog-header.php in Codeigniter's index.php page, I got a problem that site_url() is defined in both codeigniter's URL helper and WordPress. I solved this using the following code:

require('blog/wp-blog-header.php');

add_filter('site_url', 'ci_site_url', 1);

function ci_site_url() {
    include(BASEPATH.'application/config/config.php');
    return $config['base_url'];
}

header("HTTP/1.0 200 OK");

Last line needs to be added as WordPress file was adding a HTTP response header 'HTTP/1.0 404 Page not found' to the header.

Now its fine to use WordPress functions to call in CodeIgntier.

2010-02-16