Add preload attribute in wp_enqueue_script

I am trying to add attributes in :

<script src='http://localhost/projects/eviden/wp-content/themes/evidian/assets/build/fonts/Montserrat-VariableFont_wght.ttf' id='preload-custom-font-js'></script>

but it's not getting added, not sure what went wrong:

function my_style_loader_tag_filter($html, $handle)
    {
        if ($handle === 'preload-custom-font') {
            return str_replace(
                "id='preload-custom-font-js'",
                "rel='preload' as='font' type='font/ttf' id='preload-custom-font-js'",
                $html
            );
        }
        return $html;
    }
add_filter('style_loader_tag', array($this, 'my_style_loader_tag_filter'), 10, 2);

I want to add rel='preload' as='font' type='font/ttf' in the script tag getting rendered.



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation