[Support request] How to remove type attribute type=”text/css” for the style element

Home Forums Support How to remove type attribute type=”text/css” for the style element

  • This topic has 3 replies, 2 voices, and was last updated 4 months ago by Elvin.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1454963
    Ben

    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

    #1454982
    Elvin
    Customer Support

    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/

    A wise man once said:
    "Have you cleared your cache?"

    #1454999
    Ben

    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?

    #1455143
    Elvin
    Customer Support

    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.

    A wise man once said:
    "Have you cleared your cache?"

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.