我有两个来自wordpress core的渲染块JS。jquery。js和jquery迁移。最小js。下列的this answer on WPSE 我能够向调用jquery migrate和bootstrap的脚本标记中添加“defer=”defer“,但对“jquery”执行相同操作不会将defer属性添加到调用jquery的脚本标记中。js公司
add_filter( \'script_loader_tag\', function ( $tag, $handle ) {
$handlesToDefer = array(\'jquery-migrate\', \'bootstrap\', \'jquery\');
if ( !in_array($handle, $handlesToDefer) )
return $tag;
return str_replace( \' src\', \' defer="defer" src\', $tag );
}, 1, 2 );
SO网友:Chandresh Agravat
add_filter( \'script_loader_tag\', function ( $tag, $handle ) {
$handlesToDefer = array(\'jquery-migrate\', \'bootstrap\', \'jquery-core\');
if ( !in_array($handle, $handlesToDefer) )
return $tag;
return str_replace( \' src\', \' defer="defer" src\', $tag );