Can't exclude scripts from Rocket Loader in Wordpress - what am I doing wrong?

wordpress
rocketloader
#1

Hey!

I’m trying to disable Cloudflare’s Rocket Loader for specific scripts. At first I’m trying to disable it for mobile slider. I tried various combinations of this (and every other I found on StackOverflow) code:
add_filter( ‘script_loader_tag’, function ( $tag, $handle ) {

if ( 'writeup-owl-carousel' !== $handle )
    return $tag;

return str_replace( "type='text/javascript' src", ' data-cfasync="false" src', $tag     );

}, 10, 2 );

This is the code I’m trying to exclude:

if ( ! function_exists( ‘writeup_scripts’ ) ) {

function writeup_scripts() {

    wp_enqueue_script( 'writeup-owl-carousel', get_template_directory_uri() . '/js/owl.carousel.min.js', array( 'jquery' ),'', true );
}  

}

When I paste this code in functions.php, the whole element (slider) dissapears. Does anyone know what’s wrong with this code? I feel like I’ve tried everything…

Thank you,
Kacper

0 Likes

#2

I forgot to add that when I upload the code above, all javascript elements on my website become unclickable.

0 Likes

#3

@kacper3355 having Rocket Loader ignore specific scripts is only recommended if you understand the dependencies of that script - as excluding only 1 script that has other dependencies can lead to a problem.

First thing to ask is - why are you trying to have Rocket Loader ignore this script in the first place - are you seeing an error?

0 Likes