I was trying to load wordpress in a smarty template and i have got a lot of errors that has the same origin "Fatal error: Call to a member function the_function() on a non-object".

The solution to such error is by declaring the wordpress global objects before loading wordpress like this:

global $wp_rewrite;

Is there is a list of these objects that I can use to declare all of them so I don't get any of these errors again?

  • Can you give some explicit examples of what you are trying to do? You shouldn't need to modify global objects directly (and should avoid doing so). WordPress will (nearly) always provide functions for modifying global objects. Apr 9, 2012 at 1:06
  • i am trying to load wordpress in a smarty template. And i get a lot of errors. most of them like this: Fatal error: Call to a member function the_function() on a non-object
    – alhoseany
    Apr 9, 2012 at 4:01

1 Answer 1


As I've mentioned in the comments - you shouldn't need to modify / touch WordPress globals directly. It seems you are getting the errors because you are trying to load WordPress within Smart - this is a bit of a hacky approach.

I've not used Smarty at all, but WordPress has its own way of handling templates and trying to load WordPress within another framework is not going to be without its difficulties. Instead, you might consider this plug-in: http://wordpress.org/extend/plugins/smarty-for-wordpress/ which allows you to use your smarty template with WordPress. To quote the plug-in's readme:

Smarty for WordPress is the first plugin which incorporates a complete distribution of the Smarty template engine as a WordPress plug-in. You embed your Smarty template file by using a WordPress short code with the Smarty template file name and any variable which you want to be passed to your Smarty template file.

  • i am aware of this plugin but i want to do the opposite of it, i want to be able to use wordpress templates in smarty templates. this is why i am trying to load wordpress in smarty template. and i am so close to get this done. it is just the global objects errors. could you plz provide a list of these global objects?
    – alhoseany
    Apr 9, 2012 at 18:36

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.