admin管理员组

文章数量:1130349

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.

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.

本文标签: theme developmentAlternative solution for scriptloadertag