Site icon Hip-Hop Website Design and Development

How to disable CloudFlare’s Rocket Loader on scripts if the user is logged in without side effects

I’ve modified this script to add the attribute data-cfasync=’false’ to all script tags if the user is logged it. It appears to work however I seem to be having some issues with the scripts loading in later on perhaps in a different order.

// disable Cloudflare Rocket Loader if user is logged in

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

function cfrocketloader_ignore_script( $tag, $handle, $src )
{
    if ( is_user_logged_in() ) 
    {
        return str_replace( "src='", "data-cfasync='false' src='", $tag );
    }
}