我有几个脚本加载了我的主题:
// loading script.js
<script type="text/javascript" src="script.js"></script>
// doing something using script.js
<script type="text/javascript">
script-var: <?php echo get_option(\'script1-var\');?>
</script>
他们工作得很好,但当我这样做的时候
wp_enqueue_script
而不是
<script src="">
脚本在内嵌js内容后加载,因此:
// enqueuing script.js
wp_enqueue_script(\'script-js\', get_template_directory_uri() ."/scripts/script.js");
// doing something using script.js
<script type="text/javascript">
script-var: <?php echo get_option(\'script1-var\');?>
</script>
提供:
<script type="text/javascript">
script-var: <?php echo get_option(\'script1-var\');?>
</script>
<!-- EVERYTHING ABOVE THIS LINE IS USELESS SINCE THE SCRIPT LOADS AFTER, NOT BEFORE, IT -->
<script type=\'text/javascript\' src=\'http://address/scripts/script.js?ver=3.2.1\'></script>
如何避免这种情况?我知道我可以将内联脚本放入不同的文件并将它们排队,但这绝对没有意义,因为其中有很多PHP函数。