I have a script which must run in my footer, after some variables are declared. It works if I just put the code directly in my footer file, but I think best practices dictate I should do this via functions.php and wp_localize_script.

Unfortunately that doesn't work; the script is always output in the header. Any ideas on where I'm going wrong? Thanks in advance for your help!

add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_front_page_scripts' );

function mytheme_enqueue_front_page_scripts() {
        get_bloginfo('stylesheet_directory') . '/_/js/flowplayer/flowplayer-object-creator.js' );

     // last 'true' in wp_enqueue_script should force this into footer, right?
     wp_enqueue_script( 'flowplayer_object','','',true, true );

     $data = array( 'my_stylesheet_path' => __( get_bloginfo('stylesheet_directory') ) );
     wp_localize_script( 'flowplayer_object', 'my_data', $data );

1 Answer 1


You should be setting it to show in the footer with the register, so your code should look like this:

    get_bloginfo( 'stylesheet_directory' ) . '/_/js/flowplayer/flowplayer-object-creator.js',
    array(), // these are your dependencies, if you need jQuery or something, it needs to go in that array
    false, // set a version if you want
    true // this will put it in the footer

wp_enqueue_script( 'flowplayer_object' );
  • Thank you! Good to know. I'm assuming this means wp_register_script options override wp_enqueue_script options, since you can set it either place?
    – Michelle
    Feb 4, 2012 at 21:04
  • I think wp_enquque_script() has the final say...but if you set it in wp_register_script(), you don't have to set it in the enqueue
    – mor7ifer
    Feb 4, 2012 at 21:26
  • Hmm, I was setting it in wp_enqueue_script and it wasn't taking (see above). Only worked when I moved it to wp_register_script. Ah well, just glad it's working. :)
    – Michelle
    Feb 4, 2012 at 23:09
  • Except that when you set it in the enqueue, you were clearing all the other properties.
    – mor7ifer
    Feb 4, 2012 at 23:38
  • In this context, you should probably just get rid of the wp_register_script(), and put everything in wp_enqueue_script(), since it will handle the script-registering itself. Feb 5, 2012 at 2:56

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.