WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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. – Stephen Harris Apr 9 '12 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 '12 at 4:01
up vote 0 down vote accepted

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.

share|improve this answer
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 '12 at 18:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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