Site logo

Archived topic

async css

3 replies · Started by Anil on September 11, 2021

Viewing posts 1–4 of 4

how to add async word in css

<link rel=stylesheet id=generate-widget-areas-css href='https://domain.com/wp-content/themes/generatepress/assets/css/components/widget-areas.min.css' media=all>
<link rel=stylesheet id=generate-style-css href='https://domain.com/wp-content/themes/generatepress/assets/css/main.min.css' media=all>

Hi Anil,

Try adding this PHP snippet.

function add_stylesheet_attributes( $html, $handle ) {
    if ( $handle === 'generate-style' ) {
        return str_replace( "media='all'", "media='all' async", $html );
    } if ( $handle === 'generate-widget-areas' ) {
        return str_replace( "media='all'", "media='all' async", $html );
    }
    return $html;
}
add_filter( 'style_loader_tag', 'add_stylesheet_attributes', 10, 2 );

Thanks Elvin.

No problem. :)

This archived topic is closed to new replies.