• Resolved mastercavid

    (@mastercavid)


    Hi. W3c validator test tool says javascript type attribute is unnecessary. I remove them with functions.php, but when cache created, this type attributes appear again. Can we solve them?

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Anonymous User 16850768

    (@anonymized-16850768)

    To troubleshoot this, can you please provide the snippet used in your functions.php file?

    Thread Starter mastercavid

    (@mastercavid)

    add_action('wp_loaded', 'prefix_output_buffer_start');
    function prefix_output_buffer_start() { 
    	ob_start("prefix_output_callback"); 
    }
    add_action('shutdown', 'prefix_output_buffer_end');
    function prefix_output_buffer_end() { 
    	ob_end_flush(); 
    }
    function prefix_output_callback($buffer) {
    	return preg_replace( "%[ ]type=[\'\"]text\/(javascript|css)[\'\"]%", '', $buffer );
    }
    Anonymous User 16850768

    (@anonymized-16850768)

    The easiest way to make this work in my opinion would be using the Cache Enabler cache_enabler_before_store filter, for example:

    // hook callback function with Cache Enabler action
    add_filter( 'cache_enabler_before_store', 'prefix_output_callback' );
    
    // remove JS/CSS type attribute on script and source elements
    function prefix_output_callback( $data ) {
        return preg_replace( '%[ ]type=[\'\"]text\/(javascript|css)[\'\"]%', '', $data );
    }

    This will allow Cache Enabler to call your custom function (passing the page data as $data) and then receive the modified page data before the page is cached.

    Thread Starter mastercavid

    (@mastercavid)

    Cool, it is working, thanks you

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘w3c validator problem’ is closed to new replies.