script_loader_tag
WordPress 4.1中引入了过滤器:
<?php
add_filter( \'script_loader_tag\', \'my_script_attributes\', 10, 3 );
function my_script_attributes( $tag, $handle, $src )
{
// change to the registered script handle, e. g. \'jquery\'
if ( \'MY_SCRIPT_HANDLE\' === $handle ) {
// add attributes of your choice
$tag = \'<script id="customID" data-name="customDataName" src="\' . esc_url( $src ) . \'"></script>\';
}
return $tag;
}