wp_enqueue_script不起作用 [英] wp_enqueue_script not working

查看:74
本文介绍了wp_enqueue_script不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:我的custom.js在jquery之前加载并抛出错误.

Problem: My custom.js is loading before jquery and throwing an error.

我的functions.php代码设置:

My functions.php code setup:

function blue_sentry_scripts() {
    wp_enqueue_style( 'blue-sentry-style', get_stylesheet_uri() );

    wp_enqueue_script( 'blue-sentry-superfish', get_template_directory_uri() . '/js/superfish.min.js', array('jquery'), '20141010', true );

    wp_enqueue_script( 'blue-sentry-superfish-settings', get_template_directory_uri() . '/js/superfish-settings.js', array('blue-sentry-superfish'), '20141010', true );

    wp_enqueue_script( 'blue-sentry-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true );

    wp_enqueue_script( 'blue-sentry-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true ); 
    wp_enqueue_script( 'skrollr', get_template_directory_uri() . '/js/skrollr.min.js', array(), '20140928', true );

    wp_enqueue_script( 'waypoints', get_template_directory_uri() . '/js/waypoints.min.js', array('jquery'), '20141022', true );

    wp_enqueue_script( 'custom-script', get_template_directory_uri() . '/js/custom.js', array('jquery','waypoints'), '', true );

    if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
        wp_enqueue_script( 'comment-reply' );
    }
}
add_action( 'wp_enqueue_scripts', 'blue_sentry_scripts' );

如您所见,我已经声明了jquery的'waypoints.min.js'和'custom.js'的依赖关系.我相信我的代码在语法上是正确的,因为所有相关脚本实际上都在加载中.仅仅是Wordpress在加载jquery之前就忽略了排队和加载/执行我的custom.js和waypoints.js的依赖关系,而我一直无法找到解决方案!

As you can see, I have declared dependencies for both 'waypoints.min.js' and 'custom.js' of jquery. I believe my code is grammatically correct because all scripts concerned are in fact loading. It's just that Wordpress is ignoring the dependencies enqueueing and loading/executing my custom.js and waypoints.js before jquery is loaded and I have not been able to find a solution!

任何想法将不胜感激!

推荐答案

好的,它现在可以工作了,这就是我所做的:

Okay, it's working now and here's what I did:

我用过:

jQuery( document ).ready(function()

代替:

$( document ).ready(function()

我的问题解决了.这是一个解决wordpress jquery冲突的示例.

and my problem was solved. This is an example of a fix for a wordpress jquery conflict.

这篇关于wp_enqueue_script不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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