我最近在我的主题中添加了以下内容functions.php
, 要从CDN加载jQuery,请执行以下操作:
function my_init_method() {
wp_deregister_script(\'jquery\');
wp_register_script(\'jquery\', \'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js\');
}
add_action(\'init\', \'my_init_method\');
然而,这会导致管理屏幕出现问题,尤其是WYSIWYG编辑器,它拒绝允许HTML模式(通过选项卡)。我收到一个错误:
jQuery is not defined
来自wp admin/load\\u脚本。php文件。我做错了什么?
最合适的回答,由SO网友:Chris_O 整理而成
jQuery没有定义这是因为Google CDN jQuery没有处于无冲突模式。使用以下命令确保在admin中使用包含的WordPress no conflict jquery。
if( !is_admin()){
wp_deregister_script(\'jquery\');
wp_register_script(\'jquery\', ("http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"), false, \'1.4.2\');
wp_enqueue_script(\'jquery\');
}