问题
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