如何将延迟或异步属性添加到wp_add_inline_script? [英] How to add defer or async attribute to wp_add_inline_script?
本文介绍了如何将延迟或异步属性添加到wp_add_inline_script?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
首先,我使用以下命令使脚本入队:
First I enqueue a script using:
wp_enqueue_script( "script", plugins_url( "/test/js/script.js", PATH ), array("jquery"), VERSION, true );
然后我要在脚本"之后插入一个内联脚本.
Then I'm inserting an inline script after "script".
wp_add_inline_script( "script", "console.log('hello world');" );
现在我需要在嵌入式脚本中添加 defer或async属性,有没有办法对 wp_add_inline_script()嵌入的脚本执行此操作?
Now I need to add defer or async attribute to my inline script, is there a way to do this to a script embedded by wp_add_inline_script() ?
推荐答案
wp_enqueue_script("script",plugins_url("/test/js/script.js",PATH),array("jquery"),版本,true);
wp_script_add_data('script','async/defer',true);
这篇关于如何将延迟或异步属性添加到wp_add_inline_script?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文