[wp-hackers] Including javascript in the footer
Philip Walton
philip at philipwalton.com
Wed May 11 06:32:18 UTC 2011
I've tested wp_enqueue_script() and it doesn't work if called from any
action after 'wp_print_scripts' in a page request.
The Codex recommends: "Use the wp_enqueue_scripts action to call this
function, or admin_enqueue_scripts to call it on the admin side. Calling
it outside of an action can lead to troubles."
In my case I'm making a programmatic decision partway through the page
request whether or not I want to include a script in the footer, and
unfortunately, that decision is being made after the 'wp_print_scripts'
hook is fired.
So what should I do? I don't want to just echo the script markup in
'admin_print_footer_scripts' because that just seems wrong. However, I
can't really think of any other good way.
Any ideas?
More information about the wp-hackers
mailing list