javascript - Add additional attributes to script tag when enqueue script - Stack Overflow

I need Rocket loader to ignore some specific script that I enqueue using wp_enqueue_script(), So I need

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?

Share Improve this question asked May 1, 2016 at 7:42 Avishay28Avishay28 2,4666 gold badges29 silver badges53 bronze badges 1
  • wordpress.stackexchange./questions/50457/… – David Commented May 1, 2016 at 10:58
Add a ment  | 

1 Answer 1

Reset to default 6

I 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 );

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745228702a4617581.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信