为什么jquery无法与wordpress enqueue一起使用? [英] Why is jquery not working with wordpress enqueue?

查看:125
本文介绍了为什么jquery无法与wordpress enqueue一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是通过这种方法切换了将jquery放入主题的方式:

I just switched the way I enqueue jquery in a theme from this method:

function my_init() {
if (!is_admin()) {
    // comment out the next two lines to load the local copy of jQuery
    wp_deregister_script('jquery');
    wp_register_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js', false, '1.7.2');
    wp_enqueue_script('jquery');
}
}
add_action('wp_enqueue_scripts', 'my_init');

对此:

function my_scripts_method() {
wp_enqueue_script('jquery');
}
add_action('wp_enqueue_scripts', 'my_scripts_method');

function my_admin_scripts_method() {
wp_enqueue_script('jquery');
}
add_action('admin_enqueue_scripts', 'my_admin_scripts_method');

旧版本使用1.7.2,wordpress的内置版本是1.7.1.我已经尝试过将1.7.1的地址复制并粘贴到第一个版本中,但它的破坏方式是相同的.源代码中存在指向1.7.1版本的链接,但jquery无效.有什么想法可能导致这种情况吗?

The old version used 1.7.2, wordpress' built in version is 1.7.1. I have tried just copy and pasting the address for the 1.7.1 into the first version and it breaks just the same. The link is there in the source to the 1.7.1 version but jquery just does not work. Any ideas what might cause this?

网站网址:www.brainbuzzmedia.com/themes/vertex/

website url: www.brainbuzzmedia.com/themes/vertex/

推荐答案

function my_scripts_method() {
if (!is_admin()) {
    wp_enqueue_script('jquery');
 }
}
add_action('wp_enqueue_scripts', 'my_scripts_method');

function my_admin_scripts_method() {
// you don't need to load jquery here, because its automatically loaded in the adminby default 
}
add_action('admin_enqueue_scripts', 'my_admin_scripts_method');

这篇关于为什么jquery无法与wordpress enqueue一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆