Skip to content

Instantly share code, notes, and snippets.

@adamrosloniec
Created November 15, 2019 05:01
Show Gist options
  • Save adamrosloniec/59bd772829a6b1064c6fba48f634ffdf to your computer and use it in GitHub Desktop.
Save adamrosloniec/59bd772829a6b1064c6fba48f634ffdf to your computer and use it in GitHub Desktop.
WordPress - Eliminate render-blocking resources
function addRelPreloadTagToEnqueueStyles($html, $handle) {
// Put to array all styles which you want to add tag rel="preload"
$styles = ['app', 'wp-block-library', 'contact-form-7', 'cf7cf-style'];
foreach ($styles as $singleStyle) {
$html = preg_replace("/id='" . $singleStyle . "-css'/", " id='" . $singleStyle . "-css' rel='preload' as='style' ", $html);
}
return $html;
}
add_filter('style_loader_tag', 'addRelPreloadTagToEnqueueStyles');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment