Question about wp_add_inline_script()
-
I want to initialize js vars before i use them.
using
wp_add_inline_script('my-script-slug', $my_js);
initializes them after my-script is loaded, so now i write:wp_add_inline_script('jquery-core', $my_js);
This works almost always. One of my deps is jquery, so the inits are after jquery and before my script.
Now there are ‘optimizers’ that combine scripts and compress already compressed scripts and rename them, and probably also other mechanisms that remove jquery (jquery-core). So on those sites my inline script is never loaded.
previously i simple echo’ed
<script> var myVar = ... etc </script>
in the header, but that seems to be a violation of the coding rules.
How do i correct this, making sure my inits are loaded before my js file?
- The topic ‘Question about wp_add_inline_script()’ is closed to new replies.