Disable CloudFlare Rocket Loader when logged-in so it doesn't break Beaver Builder [SOLUTION]

I’ve come up with a solution to the incompatibility problem between Beaver Builder and CloudFlare.

You need to add the following code to your functions.php file or install CodeSnippets plugin and paste it into a new snippet. Basically it adds the attribute for rocket Loader to ignore all script tags when you a logged in, while to end users can benefit from the fast speeds. It appears to work well for me but would love others to test.

// 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 );
    }
}

I’m not a coder so this does need testing before applying to anything important.