allow for specifying charset="utf-8" on enqueued scripts

  1. webaware

    There is currently no way to specify that an enqueued script should have a charset attribute. Where a script includes non-ASCII characters, it should specify its character encoding so that the browser correctly interprets those characters. Web servers can be configured to send the appropriate character encoding in the header, but plugins cannot rely on users and their hosts doing this.

    I note that there is another idea under consideration for adding support for the async tag. If custom attributes on script tags were supported via an array of optional attributes, it would accommodate both these ideas.

    Alternatively, a filter in WP_Scripts::do_item() where it creates the script tag would suffice.

    Posted: 2 years ago #
  2. webaware

    Update: for anyone who needs this, there's a dirty hack from @toscho on the WordPress Stackexchange:


    add_filter('clean_url', 'wpse_38319_filterCleanURL', 11);
    * hack: add charset='utf-8' to i18n scripts
    * @param string $url
    * @return string
    function wpse_38319_filterCleanURL($url) {
        if (stripos($url, plugins_url('i18n/', __FILE__) !== false) {
            return "$url' charset='utf-8";
        return $url;
    Posted: 2 years ago #

RSS feed for this topic


You must log in to post.

  • Rating

    4 Votes
  • Status

    This idea is under consideration