WordPress.org

Forums

jQuery conflict (4 posts)

  1. novina
    Member
    Posted 2 years ago #

    Hi guys,

    I was told I have a conflict with the jquery version from my theme and the one from wordpress.

    None of the jquery plugins seem to work. Can anyone suggest a place where the jquery script is enqueued? I can't seem to find it on header. The only thing on header I see that is relative is this:

    wp_enqueue_script('jquerycyclemin', get_bloginfo('template_directory') . '/js/jquery.cycle.min.js', array());
                wp_enqueue_script('jquerycycleminall', get_bloginfo('template_directory') . '/js/jquery.cycle.all.min.js', array());
                wp_enqueue_script('jquerymenu', get_bloginfo('template_directory') . '/js/jquery.js', array());

    but that looks like it's only a partial script from jquery, do i have to enqueue the entire jquery directory somewhere tiself? or has wordpress already done it?

  2. novina
    Member
    Posted 2 years ago #

    It seems like I added the following script following another thread's advice at function.php

    function my_init() {
    if (!is_admin()) {
    wp_deregister_script('jquery');

    // load the local copy of jQuery in the footer
    wp_register_script('jquery', '/wp-includes/js/jquery/jquery.js', false, '1.3.2', true);

    // or load the Google API copy in the footer
    //wp_register_script('jquery', 'http://code.jquery.com/jquery-latest.min.js');

    wp_enqueue_script('jquery');
    }
    }

    but it doesn't seem to do anything. The theme itself doesn't seem to have proper jquery enqueue, is that possible? If it doesn't, wouldn't it inherit WordPress's?

  3. Maor Chasen
    Member
    Posted 2 years ago #

    Can you try looking at the source code for jQuery? By reading the code you supplied it seems like it does have to show up in the HTML source code. Also, try simply using WordPress' built-in jQuery by using this single line:

    wp_enqueue_script( 'jquery' );

  4. Martin Tod
    Member
    Posted 2 years ago #

    It's difficult to tell exactly what the scripts you list are linking to without your URL, but if you replace the header code you show with:

    wp_enqueue_script( 'jquery' );
    wp_enqueue_script('jquerycyclemin', get_bloginfo('template_directory') . '/js/jquery.cycle.min.js', array('jquery'));
    wp_enqueue_script('jquerycycleminall', get_bloginfo('template_directory') . '/js/jquery.cycle.all.min.js', array('jquery','jquerycyclemin'));

    you may get a better result.

    I don't see why you need to load jQuery.cycle twice though! You may want to compare the code and only load the more recent one!

    And if
    wp_enqueue_script('jquerymenu', get_bloginfo('template_directory') . '/js/jquery.js', array());
    isn't actually loading jQuery, but loading a menu script, you may want to replace it with:
    wp_enqueue_script('jquerymenu', get_bloginfo('template_directory') . '/js/jquery.js', array('jquery'));

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.