虽然其中一个答案已被接受,但我觉得以下技术可能会对某人有所帮助。
在Plugin Page 或function.php 中包含以下代码
function include_jQuery() {
if (!is_admin()) {
wp_enqueue_script('jquery');
}
}
add_action('init', 'include_jQuery');
你当然可以使用任何有意义的函数名来代替include_jQuery。
或者,您可以使用以下代码:
function include_jQuery() {
if (!is_admin()) {
// comment out the next two lines to load the local copy of jQuery
wp_deregister_script('jquery');
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js', false, '1.8.3');
wp_enqueue_script('jquery');
}
}
add_action('init', 'include_jQuery');
最后,作为一般规则,您不应将$ 变量用于jQuery,除非您使用过shortcuts 之一。下面是一个示例,说明如何使用快捷方式 jQuery 以安全地使用 $ 变量:
jQuery(function ($) {
/* You can safely use $ in this code block to reference jQuery */
});
您可能也喜欢THIS 链接,我个人从那里学习上述技术。非常感谢 Ericm Martin!