Skip to content

Instantly share code, notes, and snippets.

@seojacky
Last active December 13, 2021 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seojacky/a42e97b9d666aac4311be77958865c0e to your computer and use it in GitHub Desktop.
Save seojacky/a42e97b9d666aac4311be77958865c0e to your computer and use it in GitHub Desktop.
<?php
/* Async CSS */
add_filter( 'style_loader_tag', 'async_css_change_attribute', 10, 2 );
function async_css_change_attribute($link, $handle) {
$marks = array(
'hide-admin-bar-based-on-user-roles',
'post-views-counter-frontend',
'wsl-widget',
'slick-theme',
'slickstyle',
'rgg-style',
'rgg-simplelightbox',
'mihdan-lite-youtube-embed',
);
if(in_array($handle, $marks)) {
$link = str_replace( '\'all\'', '\'print\'', $link );
$link = str_replace( '/>', 'onload="this.media=\'all\'" />', $link );
}
return $link;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment