我正在尝试从 CDN 加载 jquery,而不是使用 wordpress 本地加载。在我的functions.php中,我已经完成了如下操作,确保它应该只发生在前端:
function replace_jquery() {
if (!is_admin()) {
wp_deregister_script('jquery');
wp_register_script('jquery2', 'https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js');
wp_enqueue_script('jquery2');
}
}
add_action('init', 'replace_jquery');
尽管如此,当我尝试登录管理区域时,我收到一堆错误,开头是:
Notice: wp_deregister_script was called <strong>incorrectly</strong>.
Do not deregister the <code>jquery</code> script in the administration area.
To target the front-end theme, use the <code>wp_enqueue_scripts</code> hook.
Please see <a href="https://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information.
(This message was added in version 3.6.0.) in /app/public/wp-includes/functions.php on line 4204
有时它不会抛出这个错误,有时它会。我究竟做错了什么?