• Resolved nicocaldo

    (@nicocaldo)


    Hi,

    I would like to add the attribute data-cfasync="false" (which is used to tell Cloudflare to disable rocket loader for that specific script) but I can’t find a way to do it

    I was trying the filter

    function wpse_script_loader_tag( $tag, $handle ) {
        if ( 'jquery' !== $handle ) {
            return $tag;
        }
    
        return str_replace( ' src', ' data-cfasync="false" src', $tag );
    }
    add_filter( 'script_loader_tag', 'wpse_script_loader_tag', 10, 2 );

    But it doesn’t work

Viewing 4 replies - 1 through 4 (of 4 total)
  • Perhaps it’s because of this code

    public function localize( $handle, $object_name, $l10n ) {
    	if ( 'jquery' === $handle ) {
    		$handle = 'jquery-core';
    	}
    Thread Starter nicocaldo

    (@nicocaldo)

    So, do I need to use

    function wpse_script_loader_tag( $tag, $handle ) {
        if ( 'jquery-core' !== $handle ) {
            return $tag;
        }
    
        return str_replace( ' src', ' data-cfasync="false" src', $tag );
    }
    add_filter( 'script_loader_tag', 'wpse_script_loader_tag', 10, 2 );

    instead?

    You can try it. Your code looks very similar to code I use for a different script.

    Thread Starter nicocaldo

    (@nicocaldo)

    it works, thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add attribute to jquery’ is closed to new replies.