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

Home Forums Support [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

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
    Staff
    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/

    #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
    Staff
    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.

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