WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to make Cloudflare's Rocket Loader work on my WP site. Everything works fine except for the WP Visual Editor. I followed the advice here but it doesn't work:

How do I add custom attributes to javascript tags in Wordpress?

Cloudflare says that in order to make Rocket Loader ignore a javascript file I need to add the data-cfasync="false" tag before my script:

<script data-cfasync="false" src="/javascript.js"></script>    


Rocket loader doesn't ignore my JS files.

Here's my code:

function rocket_loader_attributes( $url )
$ignore = array (


if ( in_array( $url, $ignore ) )
{ // this will be ignored
return "$url' data-cfasync='false";

return $url;
add_filter( 'clean_url', 'rocket_loader_attributes', 11, 1 );

What is wrong with my code?

I'm currently using Rocket Loader on Automatic mode.

Can anyone help?

@toscho if you see this maybe you can point me in the right direction.

Thank you.

share|improve this question

Notice in the example that the tag does not have the type='text/javascript' attribute. For some reason Rocket Loader requires data-cfasync='false' to be used without the type='text/javascript'... a bug?

Your code does add the data-cfasync='false' attribute, but does not override the WordPress behaviour of adding the type='text/javascript' attribute also, which makes Rocket Loader not to "ignore" your script.

It might be tricky to override this WordPress behaviour since the relevant code does not support a filter...

share|improve this answer

You can achieve the desired result with the following function (replace script-handle with your script's handle):

add_filter( 'script_loader_tag', function ( $tag, $handle ) {

    if ( 'script-handle' !== $handle )
        return $tag;

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

The above WordPress filter grabs a script by it's handle and allows you to add/edit script attributes.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.