wp enqueue inline script due to dependancies

Well, you have wp_localize_script(), but that’s only for passing data.

Otherwise, you can do this:

function print_my_inline_script() {
  if ( wp_script_is( 'some-script-handle', 'done' ) ) {
?>
<script type="text/javascript">
// js code goes here
</script>
<?php
  }
}
add_action( 'wp_footer', 'print_my_inline_script' );

The idea is that you shouldn’t rely on your inline script being printed exactly after the script it depends on, but later.

Leave a Comment