/ Published in: PHP
passing php variables to javascript with build-in function 'wp_localize_script'.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//include js-file static !important wp_enqueue_script('js-script','/path/to/whatever.js',...); //php variables 'foo' => 'bar', 'number' => 123, ); //build in function wp_localize_script( 'js-script', 'NameForParamsInJava', $params ); //in js-code now use NameForParamsInJava.foo NameForParamsInJava.number