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 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料