Php 如果使用wp_enqueue_脚本添加脚本,如何绕过CloudFlare火箭脚本?

Php 如果使用wp_enqueue_脚本添加脚本,如何绕过CloudFlare火箭脚本?,php,wordpress,cloudflare,rocketscript,Php,Wordpress,Cloudflare,Rocketscript,我只是在谷歌上搜索了一下,但没有检索到任何具体信息。我在WordPress的PHP模板上有这样的代码: <?php wp_enqueue_script( 'jquery-carousel', get_template_directory_uri().'/js/jquery.carouFredSel-6.2.1-packed.js', array('jquery'),'',true); ?> 如果需要在此函数中添加更多标记,如“jquery-carousel1”、“jquery-ca

我只是在谷歌上搜索了一下,但没有检索到任何具体信息。我在WordPress的PHP模板上有这样的代码:

<?php wp_enqueue_script( 'jquery-carousel', get_template_directory_uri().'/js/jquery.carouFredSel-6.2.1-packed.js', array('jquery'),'',true); ?>
如果需要在此函数中添加更多标记,如“jquery-carousel1”、“jquery-carousel2”,则代码如下所示:

function add_data_attribute( $tag, $handle, $src ) {
    if( ! in_array( $handle, array( 'jquery-carousel', 'jquery-carousel1', 'jquery-carousel2' ) ) )
       return $tag;

    return str_replace( 'src', 'data-cfasync="false" src', $tag );
}

add_filter( 'script_loader_tag', 'add_data_attribute', 10, 3 );

您可以尝试使用过滤


通过这种方式,您可以针对特定的排队脚本。

谢谢Mary,这真的帮助了我。还有一件事是,如果我想在列表中添加更多内容,我如何编辑if('jquery carousel'!==$handle),并在此处添加其他内容,如-'jquery ui脚本'和'jquery tools forms脚本'?如何在那里添加多个标记?如果句柄数组中不存在句柄,可以设置条件<代码>如果(!in_array($handle,array('jquery ui script','jquery tools forms script'))感谢您的帮助,这很有效!我将更新该函数以供其他人查看。
function add_data_attribute( $tag, $handle, $src ) {
    if( ! in_array( $handle, array( 'jquery-carousel', 'jquery-carousel1', 'jquery-carousel2' ) ) )
       return $tag;

    return str_replace( 'src', 'data-cfasync="false" src', $tag );
}

add_filter( 'script_loader_tag', 'add_data_attribute', 10, 3 );
function add_data_attribute( $tag, $handle, $src ) {
    if ( 'jquery-carousel' !== $handle )
       return $tag;

    return str_replace( ' src', ' data-cfasync="false" src', $tag );
}

add_filter( 'script_loader_tag', 'add_data_attribute', 10, 3 );