paper-leaf/waldo

Issue when using in header.php

Closed this issue · 2 comments

First of all: Great approach you have chosen here, perfectly fits my workflow using ACF and came in very handy for setting responsive fullpage-background images, very much appreciated.

I ran into an issue when trying to call waldo in my header.php – the variable is marked as undefined and thus it breaks the page. Pretty sure this has to do with the load-order / initialization since it works fine when using the same code in a regular page.php-template.

My theme (Sage) calls head.php first which contains wp_head(); and my header.php follows which means that add_action('wp_head', 'init_waldo', 99); should be correctly registered / called upon beforehand...? Raising the priority didn't help.

My workaround is to call waldo in the page template while the corresponding background-div can still reside in header.php but I wanted to ask why you think this might be happening.

Thanks!

Hey @E-VANCE, thanks for the kind words! I'm glad Waldo has been workable solution for you.

I've looked into this, and as far as I can determine, WordPress doesn't allow implicit global variable access within the header.php and footer.php files.

The solution to this is to explicitly declare/pull-in the globals that you are trying to access at the beginning of the include/theme file that is having problems accessing the variables.

This may be done by including: global $waldo, $waldo_styles; or $waldo = $GLOBALS['waldo']; $waldo_styles = $GLOBALS['waldo_styles'];.

From there, you should be able to proceed with the code as per the documentation example.

Thanks for getting back and updating the README accordingly! Sorry for the late reply, the issue somehow slipped my mind after I got things working...