显示错误 tinymce 的控制台未在 Wordpress 上定义

Console showing error tinymce is not defined on Wordpress

我对 Wordpress 管理员有疑问。我无法添加新的 post 或页面,控制台显示 'Uncaught ReferenceError: tinymce is not defined'.

我发现我的 functions.php 上的函数 'script_loader_tag' 导致了错误(没有它一切正常)但我不知道我做错了什么。

这些是 JS 函数:

    function loadJS() {
      wp_register_script('custom-js', get_template_directory_uri() . '/js/scripts.js');
      wp_enqueue_script('custom-js');
    }   

    add_action('wp_enqueue_scripts', 'loadJS');


    function add_module_to_script($tag, $handle, $src) {
      if('custom-js' !== $handle ) {
      return $src;
    } 
    $tag = '<script type="module" src="' . esc_url($src) . '"></script>';
    return $tag;
    }

    add_filter('script_loader_tag', 'add_module_to_script', 10, 3);

当句柄不等于“custom-js”时,您必须确保不更改 $tag。你应该 return $tag,而不是 $src.

function add_module_to_script($tag, $handle, $src) {
    if('custom-js' !== $handle ) {
      return $tag;
    } 

    $tag = '<script type="module" src="' . esc_url($src) . '"></script>';

    return $tag;
}

add_filter('script_loader_tag', 'add_module_to_script', 10, 3);

更好。

function add_module_to_script($tag, $handle, $src) {
    if('custom-js' == $handle ) {
      $tag = '<script type="module" src="' . esc_url($src) . '"></script>';
    } 

    return $tag;
}

add_filter('script_loader_tag', 'add_module_to_script', 10, 3);