dougou6114 2016-02-27 18:57
浏览 84

为什么我使用自定义主题打开WordPress页面时会出现此JQuery错误?

I am pretty new as WordPress developer and I have the following problem.

I have create the template of this website starting from 0 by myself: http://www.asper-eritrea.com

Now I have add this photo gallery plugin: https://wordpress.org/plugins/robo-gallery/

The problem is that now, when I access to a page that use this plugin, for example: http://www.asper-eritrea.com/photo-gallery/

the gallery is not shown and, into the FireBug console, I obtain this error message:

TypeError: $ is not a function
    $(document).ready(function() {

So I think that maybe it could depende by the fact that it can't retrieve JQuery, but I am absolutly not sure about it because I have the same error also opening the others page of my website so I am not sure that the missing of JQuery into the photogallery page is the cause of my problem.

Into the function.php file of my template I have the following function that enqueue all the JavaScript resources (including JQuery), in this way:

/* Hooks a function on to a specific action (an action is a PHP function that is executed at specific
 * points throughout the WordPress Core)
 * @param 'wp_enqueue_scripts': The name of the action to which 'wpb_adding_styles' is hooked (wp_enqueue_scripts
 *        is the proper hook to use when enqueuing items that are meant to appear on the front end)
 */
add_action('wp_enqueue_scripts', 'wpb_adding_styles');

/* Function automatically executed by the hook 'load_java_scripts':
 * 1) Load all my JavaScripts
 */
function load_java_scripts() {

    // Load JQuery:
    wp_enqueue_script('jquery');
    // Load FlexSlider JavaScript
    wp_enqueue_script('flexSlider-js', get_template_directory_uri() . '/assets/plugins/flexslider/jquery.flexslider.js', array('jquery'), 'v2.1', true);
    // Load bootstrap.min.js:
    wp_enqueue_script('bootstrap.min-js', get_template_directory_uri() . '/assets/bootstrap/js/bootstrap.min.js', array('jquery'), 'v3.0.3', true);

    // Load FancyBox:
    wp_enqueue_script('fancy-js', get_template_directory_uri() . '/assets/plugins/fancybox/jquery.fancybox.pack.js', array('jquery'), 'v2.1.5', true);
    // Load scripts.js:
    wp_enqueue_script('myScripts-js', get_template_directory_uri() . '/assets/js/scripts.js', array('jquery'), '1.0', true);
    // Load Modernizer:
    wp_enqueue_script('myodernizer-js', get_template_directory_uri() . '/assets/js/modernizr.custom.js', array('jquery'), '2.6.2', true);

}

add_action('wp_enqueue_scripts', 'load_java_scripts');

So what is wrong? What am I missing?

The strange thing is that to enqueue JQuery there is:

wp_enqueue_script('jquery');

but there is not specified the exact folder of the Jquery source file (as done for the other resources).

I have JQuery putted into the /assets/bootstrap/js/jquery.js file.

  • 写回答

1条回答 默认 最新

  • doufen1933 2016-02-27 19:07
    关注

    Wordpress generally includes jQuery.noConflict() which removes the $ alias to prevent collisions with other libraries that may also be using $

    Change:

     $(document).ready(function() {
    

    To

    jQuery(document).ready(function($) {
    
         // OK to use `$` here
    
    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况