theme development - Alternative solution for script_loader_tag?

admin2025-06-05  2

Theme check plugin gives me this error

Found script_loader_tag in the file functions.php. Do not remove core functionality.

I have used it to defer scripts

function add_defer_attribute($tag, $handle) {
$scripts_to_defer = array(
                           'jquery_table_js',
                           'searchautocompleter',
                           'jquery-migrate',                           
                           );

      if (in_array($handle, $scripts_to_defer))  return str_replace(' src', ' defer="defer" handeler="'.$handle.'" src', $tag);

 return str_replace(' src', ' handeler="'.$handle.'" src', $tag);
}

add_filter('script_loader_tag', 'add_defer_attribute', 100, 2);

this works fine but seems not allowed to do so.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749081696a316202.html

最新回复(0)