Is there an easy way to enqueue a JavaScript file with url_query values populated?
I have a php file underneath my js directory with JavaScript headers that I want to generate some dynamic JavaScript depending on the url_query values.
Thanks
Gs
UPDATE:
Yes, in the widget class I added the following (as a test):
(in the constructor, I just wanted to make a completely unique ID so I took the timestamp + a bunch of random #s):
$this->widget_id=time().rand(2,10).rand(2,10).rand(2,10).rand(2,10).rand(2,10).rand(2,10);
add_action('wp_footer', array( &$this, 'footer_js' ));
(then the method):
public function footer_js(){
wp_register_script( 'mgs-site-script'.$this->widget_id, $this->plugin_location . "js/mgs.js", array('jquery'),'1.2.0');
wp_enqueue_script( 'mgs-site-script'.$this->widget_id );
$translation_array = array( 'some_string' => __( 'Some string to translate' ), 'a_value' => '10' );
wp_localize_script( 'mgs-site-script', 'object_name', $translation_array );
}
Then in mgs.js I tried to access the variables by calling:
alert(object_name.some_string);
but firebug spits out "object_name is not defined"
wp_localize_script
? Its a easy way to passing variables/values to javascript file. Not via url parameter though. It creates a global object. codex.wordpress.org/Function_Reference/wp_localize_scriptwp_enqueue_script()
function to thewp_enqueue_script
hook, you're asking for trouble. It comes with an $in_footer parameter which it seems you'd take advantage of.