I'm trying to make JS and CSS asynchronous without plugins(I know this is possible, without much of coding).
As I'm not really know php, I would like you to help me a little bit over here.
I found this code, to handle this kind of thing, but I don't really understand how to use it.
function add_async_attribute($tag, $handle) {
$scripts_to_async = array('my-js-handle', 'another-handle');
foreach($scripts_to_async as $async_script) {
if ($async_script !== $handle) return $tag;
return str_replace(' src', ' async="async" src', $tag);
}
return $tag;
}
add_filter('script_loader_tag', 'add_async_attribute', 10, 2);
What should I place exactly instead of my-js-handle
or another-handle
if JQuery file placed here: wordpress/wp-includes/js/jquery/jquery.js?ver=1.11.3
?
Also, if I'll enlarge the array, say like this:
array('my-js-handle', 'another-handle', 'one-more');
Would I need to change something, say this(in the end of add_filter
): 10, 2);
?
And as for the css asynchronization... would it be enough to simply enlarge this array and add mine css address?