I have seen script_loader_tag function applied in functions.php, WordPress, but I struggle to understand completely how does it work.
For example, I've seen examples like this:
function add_async_defer($tag, $handle) {
if('googlemaps' !== $handle) {
return $tag;
}
return str_replace(' src', 'async="async" defer="defer" src', $tag);
}
add_filter('script_loader_tag', 'add_async_defer', 10, 2);
and it is used to generate the script tag for Google Maps API:
<script type='text/javascript'async="async" defer="defer" src='https://maps.googleapis.com/maps/api/js?key=AIzaSyBz02VRxO_dgaKsBS62TLL6AW4McNTQiKU0callback=initMap&ver=5.2.1'></script>
But what does the $tag and $handle parameters mean?
What does numbers 10 and 2 mean in the end of the add_filter?
Can this function be modified to display the tag conditionally only in the specific pages?