Archived topic
How to remove type attribute type="text/css" for the style element
3 replies · Started by Ben on September 23, 2020
Any ideas on how we can remove the type attribute for the style element that is used in simple-css plugin ?(love the plugin btw)
<style type="text/css" id="simple-css-output">
should be
<style id="simple-css-output">
Many thanks
Ben
Hi Ben,
You can try this PHP code:
add_action( 'after_setup_theme', function() {
add_theme_support( 'html5', [ 'script', 'style' ] );
});
This PHP code will remove all the type attributes from <script> and <style> tags on the entire page.
Here's how to add PHP - https://docs.generatepress.com/article/adding-php/
That's already in there and works on everything EXCEPT simple css plugin.
I can see in the actual plugin it has the line 231
// Finally, print it
echo '<style type="text/css" id="simple-css-output">';
echo strip_tags( $output );
echo '</style>';
Any way to override or filter this?
Oh, alright.
You can try this out. Reference: https://stackoverflow.com/a/50853611
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 );
}
This one does scans through things after load.