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!

1 Answer 1


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.

  • 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. Commented Jan 23, 2013 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? Commented Jan 23, 2013 at 20:51
  • Can you post the code of your Plugin please?
    – fischi
    Commented Jan 24, 2013 at 5:21

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.