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:
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?
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
you will get all the variables passed in loader object of CI.
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
asglobal
before callingget_header()
. Now my code looks like the following:CI View file (header.php):
WP function
wp_title()
ingeneral-template.php
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.