Dynamic data in `wp_register_script` needed

You are looking for the wp_localize_script() function. This function allows you to add data from server to your javascript.

However, this will not change the content of jsfile.js. Instead, it will add some global variable in your theme’s footer.Changing the content of a JS file before outputting it to the browser is an advanced technique, and requires compiling/buffering. The above function should be enough for most of the users.

Everything you need about how to use the function is included in the provided link.

Leave a Comment