开发

给 WordPress 输出的 script 标签添加 type = “module”

lined-script 为输出时设定的标签名

add_filter( 'script_loader_tag', function ( $tag, $handle, $src ) {
  switch ( $handle ) {
    case 'lined-script':
      return '<script type="module" src="' . esc_url( $src ) . '"></script>';
      break;
    default:
      return $tag;
      break;
  }
}, 10, 3 );

PUJI Design 朴及设计 (c) 2024. 沪ICP备17052229号