0

This is pretty simple to filter a specific css file's link. But I want to filter all except style.css using: add_filter( 'style_loader_tag', 'remove_https_http', 10, 4 ); recursively to deliver optimized css and high score on page speed and load time.

 add_filter( 'style_loader_tag',  'remove_https_http', 10, 4 );
    function remove_https_styles( $html, $handle, $href, $media ){
        $handles = array('twentysixteen-fonts', 'open-sans');
        if( in_array( $handle, $handles ) ){
            $html = str_replace('https:', '', $html);   
        }
        return $html;
    }

This will be great if there is others approach. I already study on: CSS delivery optimization: How to defer css loading?. But it seems to me filtering all css links which can be loaded after rendering my page, suggested by : https://developers.google.com/web/fundamentals/performance/critical-rendering-path/render-blocking-css.

Any idea will be a great tool tip. Thanks in advance.

Abdus Sattar Bhuiyan
  • 3,016
  • 4
  • 38
  • 72

1 Answers1

1

Add following code in functions.php file of the theme.

function theme_styles()  
{ 
  // Register the style like this for a theme:  
  // (First the unique name for the style (custom-style) then the src, 
  // then dependencies and ver no. and media type)
  wp_enqueue_style( 'style-css', get_template_directory_uri() . '/style.css', array(), '1.2', 'print' );
}
add_action('wp_enqueue_scripts', 'theme_styles');

Hope this help and let me know in case of any query.

PPL
  • 6,357
  • 1
  • 11
  • 30