enqueue and localize script in footer

You should be setting it to show in the footer with the register, so your code should look like this: wp_register_script( ‘flowplayer_object’, 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 … Read more

wp_localize_script $handle

It’s basically a unique id of the script you registered or enqueued before. Let’s say we enqueued a two scripts with wp_enqueue_script(): wp_enqueue_script( ‘my_script_1′,’/js/some_script.js’ ); wp_enqueue_script( ‘my_script_2′,’/js/some_other_script.js’ ); Now you want to pass your $data to the script #2 with wp_localize_script(): wp_localize_script( ‘my_script_2’, ‘my_script_2_local’, $data ); After this – when WordPress prints out your my_script_2 … Read more

wp_localized_script is not defined when called via jquey ajax

To successfully add variable to the window object via wp_localize_script you need to properly invoke three functions in the following sequence: wp_register_script wp_localize_script wp_enqueue_script In your case you’re missing the wp_register_script. In case someone experiences the same issue, follow the code procedures below. PHP <?php function my_theme_wp_enqueue_scripts() { $handle=”my_handle”; // Register the script wp_register_script($handle, ‘/path/to/my_script.js’); … Read more

What is the correct way to build a widget using OOP

You can simply put your init code within the constructor of the class. For example: class myWidget extends WP_Widget{ function myWidget(){ // Init code here } function widget( $args, $instance ) { // The widget code wp_enqueue_script(…); wp_enqueue_style(…); } // Over methods… } register_widget(‘myWidget’); My preference is to actually put the enqueue calls within the … Read more

Passing boolean values with wp_localize_script

Try this: $options = get_option( ‘theme’ ); wp_localize_script( ‘flexslider’, ‘flex_vars’, array ( ‘flex_auto’ => ($options[‘slide-auto’]) ? ‘true’ : ‘false’, ‘flex_animation’ => $options[‘slide-animation’], ‘flex_direction’ => $options[‘slide-direction’] ) ); Assuming slide-auto is the option you made a boolean. This script isn’t tested, I directly typed it in here.