// Register script as per Codex instructions.
// It doesn't have to contain anything but the file must exist
wp_register_script('handle', get_template_directory_uri() .'/js/dummy.js');
// Send data to client
wp_localize_script('handle', 'Data', array(
'url' => home_url(),
));
这将在 JavaScript 中打印一个对象:
<script type='text/javascript'>
/* <![CDATA[ */
var Data = {"url":"http://..."};
/* ]]> */
</script>