admin管理员组文章数量:1415673
I need Rocket loader to ignore some specific script that I enqueue using wp_enqueue_script()
, So I need to add data-cfasync="false"
to the script tag. But since I enqueue a js file via function.php
, I have no tag to add this to it.
Is there any way to do that?
I need Rocket loader to ignore some specific script that I enqueue using wp_enqueue_script()
, So I need to add data-cfasync="false"
to the script tag. But since I enqueue a js file via function.php
, I have no tag to add this to it.
Is there any way to do that?
- wordpress.stackexchange./questions/50457/… – David Commented May 1, 2016 at 10:58
1 Answer
Reset to default 6I had a similar problem and this code added the attribute correctly.
Add this code snippet to your functions.php file to disable cloudfare for your specific script only. Just change YOUR_SCRIPT_HANDLE_HERE accordingly.
function disable_rocketship( $tag, $handle, $src ) {
if ( 'YOUR_SCRIPT_HANDLE_HERE' === $handle ) {
$tag = str_replace( 'src=', 'data-cfasync="false" src=', $tag );
}
return $tag;
}
add_filter( 'script_loader_tag', 'disable_rocketship', 10, 3 );
本文标签: javascriptAdd additional attributes to script tag when enqueue scriptStack Overflow
版权声明:本文标题:javascript - Add additional attributes to script tag when enqueue script - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745228702a2648727.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论