[wp-hackers] [ wp-hackers ] wp _ enqueue _ script() not working while in the Loop

scribu scribu at gmail.com
Wed Dec 16 22:18:03 UTC 2009


Here's how I would conditionally load javascript using the WP script loader:

function register_my_scripts() {
wp_register_script('my-script', etc...);
}

add_action('template_redirect', 'register_my_script');


...


// in the shortcode handler:

$GLOBALS['load_my_script'] = true;


...


function print_my_script() {
global $wp_scripts, $load_my_script;

if ( $load_my_script )
$wp_scripts->do_items('my-script');
}

add_action('wp_footer', 'print_my_script');


I hope you get the gist of it.


-- 
http://scribu.net


More information about the wp-hackers mailing list