How to integrate WordPress template with CodeIgniter


Question

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?

1
45
11/28/2013 12:55:56 AM

Accepted Answer

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.

31
11/28/2013 12:56:21 AM

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.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon