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 script is responsible for the element that I'm trying to exclude from rocket loader:
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 and every javascript element on my website becomes unclickable. Does anyone know what's wrong with this code? I feel like I've tried everything...
data-cfasync="false"
attribute to the jQuery library as well, otherwise Owl Carousel will get loaded before jQuery library