Passing codeigniter variable to wordpress theme file

I have installed wordpress in my root directory and codeigniter in a sub directory and everything works fine. I can call the CI controllers and all. However, I also want to use the same wordpress theme. eg: get_header(), get_sidebar() and get_footer().

An example use would be to pass in my codeigniter page title so that wordpress does not show a Page not found title when accessing my codeigniter side. I have the following code:

Read More

A CI Controller:

public function index(){ 
    $data['ci_title'] = 'some title'; 
    $this->load->view('header', $data);
}

The CI view (header.php):

<?php get_header(); ?>;

WordPress theme file (header.php):

<title>
    <?php
        if($ci_title) echo $ci_title else wp_title('');
    ?>
</title>

Now the problem is my $ci_title isn’t being read in the wordpress theme file. I even tried putting globlal $ci_title in the get_header() function, but there it again calls some load_template() function.

Is there an easy way to pass CI variables to wordpress theme files?

Related posts

Leave a Reply

2 comments

  1. You don’t really have to go and modify the core files. What you have to do is just simply add the following lines of code in your header.php

    $CI = &get_instance(); 
    echo $CI->load->get_var('ci_title');
    

    you will get all the variables passed in loader object of CI.

  2. Ok after going through alot and finally reading http://www.php.net/manual/en/language.variables.scope.php#98811 , found out I needed to declare my $ci_title as global before calling get_header(). Now my code looks like the following:

    CI View file (header.php):

    global $ci_title;
    get_header();
    

    WP function wp_title() in general-template.php

    function wp_title($sep = '&raquo;', $display = true, $seplocation = '', $ci_title = '') {
    global $wpdb, $wp_locale, $ci_title;
    //existing code.. and at the end
    if($ci_title != ''){
    $title = $ci_title;
    

    Don’t know if it’s the right way to do it since I am just a beginner in PHP, but right now it serves my purpose. Would be nice if there was a better way though, something which makes me avoid modifying the wordpress functions.