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

First of all, I'm completely sure I'm being an idiot on this one - but an hour of scratching my head and searching this site has still left me perplexed.

I'm trying to access a constant that's defined within the constructor of my plugin in an included file. The file is included in a function that's hooked to the wp_footer action:

class className {
function className () {

function __construct() {
    DEFINE('IMPACTMENU_IMAGES', WP_PLUGIN_URL . '/impactmenu/images'); 
    DEFINE('IMPACTMENU_TEMPLATES', WP_PLUGIN_URL . '/impactmenu/templates');

    add_action('wp_footer', array($this, 'impact_menu_html'));

function impact_menu_html() {
    include(IMPACTMENU_TEMPLATES . '/template.php');
    $im_footer = ob_get_contents();
    echo $im_footer;

And in the template.php file:


I'm expecting the output to be the path to the images directory, but the output is actually simply "IMPACTMENU_IMAGES".

Any help on this would be greatly appreciated!

share|improve this question

The Problem here is that the Template Files get processed before the wp_footer action, so your constant is not defined at that stage.

Just to be sure, try hooking your constructor of the class to an action that is called earlier, I don't really know how early you need it, but try init. You could also construct your class when the Plugin is loaded, then you should be on the safe side.

share|improve this answer
Thanks! I must be getting a bit confused with this because I thought that the loading order must have been the problem so moved the constant definitions to another function and hooked that to init, yet the same result. – Paul McCarthy Jan 23 '13 at 17:02
I'm a bit confused by this - why does the IMPACTMENU_TEMPLATES constant work whereas the constant that's included after this point doesn't work? At what point are includes processed? – Paul McCarthy Jan 23 '13 at 20:51
Can you post the code of your Plugin please? – fischi Jan 24 '13 at 5:21

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.