How to add defer or async attribute to wp_add_inline_script?

帅比萌擦擦* 提交于 2020-12-06 04:12:12

问题


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() ?


回答1:


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

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

see more



来源:https://stackoverflow.com/questions/49282112/how-to-add-defer-or-async-attribute-to-wp-add-inline-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!