Make wp_localize_script() work properly
4wp_localize_script($handle, $object_name, $l10n);
For example:
$myvars = array('value' => 'one');
wp_localize_script('my-handle', 'myVars', $myvars);
The above code won't do anything unless you enqueue a script with the same handle before it, like this:
wp_enqueue_script('my-handle', 'path-to-js-file.js');
$myvars = array('value' => 'one');
wp_localize_script('my-handle', 'myVars', $myvars);
This code will be inserted into your page:
/* <![CDATA[ */
var myVars = {
value: "one"
};
/* ]]> */
Then you can reference myVars in your script later on.
great article, it help me to solve my plugin problem. thanks a lot.
Glad it helped :)
many thank, problem solved
many thanks, problem solved