I'm building a website that uses Wordpress as the CMS and is built with Yii framework. All the business logic works fine. Most visible pages are filled with content from Wordpress admin and only the user profile section is built with Yii.

My problem is that I would like to reuse the layout of the wordpress pages in the Yii app. Initially I tried to do it in a blank PHP file and everything worked as expected with this code:

require( '/var/www/wordpress/wp-load.php' );


some content here


The problem is that when I make a new layout in Yii so that I can reuse the header and footer it crashes and displays blank page. I tried both with require('/var/www/wordpress/wp-blog-header.php'); and require( '/var/www/wordpress/wp-load.php' );. This is the code I use to load wordpress functionality in Yii but unfortunately it does not work.

<?php /* @var $this Controller */
require( '/var/www/wordpress/wp-load.php' );

spl_autoload_register(array('YiiBase', 'autoload'));


All I see is a completely blank page (no markup).

Any help would be much appreciated. Ideally I would like to use get_header() and get_footer() wordpress functions in Yii layouts/views.



I checked Apache logs and it seems that the following error is logged when I try to open the page in my browser: PHP Fatal error: Call to a member function get() on a non-object in /var/www/wordpress/wp-includes/query.php on line 27 Also when I comment out the get_header(); row the page opens without any errors (and without any styling too). So something prevents get_header() to work property in Yii.

  • Disable all the plugins and check again.
    – Wyck
    Jan 7, 2013 at 3:41

2 Answers 2


In your header.php you are probably using wp_title(). This one requires at least two global variables: $wpdb (the get_query_var() call) and $wp_locale, on singular views a global $post object too.

So you have to create these variables, or set wp_title() in a conditional, like this:

if ( ! empty ( $GLOBALS['wpdb'] ) )
  • Then how does the same code works outside of Yii framework? Jan 7, 2013 at 7:17
  • @PavelNikolov No idea, $wpdb is required as you can see by the source code.
    – fuxia
    Jan 7, 2013 at 11:40

I ended up adding require( '/var/www/wordpress/wp-load.php' ); in the Yii's index.php file just before the initialization code. Then I was able to use all WordPress functions in my project. This helped me reuse the header and footer layout from WordPress in Yii using the get_header() and get_footer() functions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.