Home / Admin / Defer or Async CSS Loading
Duplicate Snippet

Embed Snippet on Your Site

Defer or Async CSS Loading

Defer or Async CSS Loading

Code Preview
php
<?php
function async_css($tag, $handle) {
    // Add 'async' to CSS file that you want to load asynchronously
    if ('your-style-handle' !== $handle) {
        return $tag;
    }
    return str_replace(' href', ' async="async" href', $tag);
}
add_filter('style_loader_tag', 'async_css', 10, 2);

Comments

Add a Comment