duanpi7578 2015-05-19 12:22
浏览 6

用charset在wordpress中排队js

I have script

<script src="js/app/script.js" charset="iso-8859-1"></script>

I need to enqueue this js in wordpress with charset. How can I do it ?

I tried do it like that

    private static function includeScriptWithCharset($path, $charset){
        //  I need      charset="iso-8859-1"
        wp_enqueue_script ($path, plugins_url($path). " ". $charset);
    }
  • 写回答

1条回答 默认 最新

  • donglisi8644 2017-11-27 15:14
    关注

    I know this question is quite old now, however I have the answer for this, in case this still helps Serg, or helps anyone else who comes across this issue.

    The way to do this is to use the WordPress 'script_loader_tag' hook as follows:

    // First enqueue your scripts as follows:
    
        wp_enqueue_script( 'my-script-handle', get_stylesheet_directory_uri() . '/some.js', array( 'jquery' ), '6.0');
        wp_enqueue_script( 'my-other-handle', get_stylesheet_directory_uri() . '/someother.js', array( 'jquery' ), '6.0');

    // Next use the script loader hook as follows:
    
    function my_async_scripts( $tag, $handle, $src ) {
        // the handles of the enqueued scripts we want to async
        $async_scripts = array( 'my-script-handle', 'my-other-handle' );
    
        if ( in_array( $handle, $async_scripts ) ) {
            return '<script type="text/javascript" src="' . $src . '" charset="iso-8859-1"></script>' . "
    ";
        }
    
        return $tag;
    }
    add_filter( 'script_loader_tag', 'my_async_scripts', 10, 3 );

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错