简体   繁体   English

如何将延迟或异步属性添加到wp_add_inline_script?

[英]How to add defer or async attribute to 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');" );

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() ? 现在我需要将defer或async属性添加到我的内联脚本中,有没有办法对wp_add_inline_script()嵌入的脚本执行此操作?

wp_enqueue_script( "script", plugins_url( "/test/js/script.js", PATH ), array("jquery"), VERSION, true );

wp_script_add_data( 'script', 'async/defer' , true );

查看更多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM