Return to Snippet

Revision: 31087
at August 29, 2010 17:26 by screamwork


Initial Code
//include js-file static !important
wp_enqueue_script('js-script','/path/to/whatever.js',...);

//php variables
$params = array(
  'foo' => 'bar',
  'number' => 123,
);

//build in function
wp_localize_script( 'js-script', 'NameForParamsInJava', $params );

//in js-code now use 
NameForParamsInJava.foo
NameForParamsInJava.number

Initial URL

                                

Initial Description
passing php variables to javascript with build-in function 'wp_localize_script'.

Initial Title
passing parameter from php to js in wordpress

Initial Tags
wordpress

Initial Language
PHP