logo

$5
Prevent Wordpress from adding jQuery?

Hi There,

I am building a custom wordpress site for a client of mine. For whatever reason wordpress is automatically loading the default jQuery script into header.php. I need to load my own jquery script rather than the default script.

Here is the code I am using to call in my javascript. This is a separate PHP file which I have included into my functions.php file. All of the scripts get loaded in perfectly besides for the first one, "jquery.min.js". Instead wordpress is loading its own jquery.

How can I prevent wordpress from adding the default jQuery? I would like to load all of my javascript files just as I've listed them below.

I really appreciate your help.




<?php
function THEME_scripts() {
wp_enqueue_script( 'jquery', THEME_JS .'/jquery.min.js', array('jquery'));
wp_enqueue_script( 'jquery-accordion', THEME_JS .'/jquery.cycle.all.2.74.js', array('jquery'));
wp_enqueue_script( 'cufon', THEME_JS .'/cufon.js', array('jquery'));
wp_enqueue_script( 'cufon-fonts', THEME_JS .'/cufon-fonts.js', array('jquery'));
wp_enqueue_script( 'cufon-settings', THEME_JS .'/cufon-settings.js', array('jquery'));
wp_enqueue_script( 'THEME-custom', THEME_JS .'/home_modules.js', array('jquery'));
}

add_action('wp_print_scripts', 'THEME_scripts');
?>

WP Answers | 08/28/10 at 8:54pm | Edit


(4) Possible Answers Submitted...

  • avatar
    Last edited:
    08/28/10
    10:54pm
    flashingcursor says:

    WordPress already has jquery registered as a script, so if you want a different jquery to load, you need to deregister it first:

    wp_deregister_script( 'jquery' );
    wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js');

    Replace the googleapis location with whichever you want to use.

    • 08/28/10 9:07pm

      WP Answers says:

      Ok Thank you. Would I add this to my custom PHP file that I listed above?

    • 08/28/10 9:09pm

      flashingcursor says:

      Yes

      function my_init_method() {
      wp_deregister_script( 'jquery' );
      wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js');
      }

      add_action('init', 'my_init_method');

      That code should do exactly what you need. Notice that we add_action on init to deregister / register a new script, so you can't just add it to your function.

    • 08/28/10 9:14pm

      flashingcursor says:

      Also, once you deregister and register your version of the script, all you have to do to call it is

      wp_enqueue_script( 'jquery');

      The additional options are unnecessary.

    • 08/28/10 9:28pm

      WP Answers says:

      Thank you very much. Everything is now getting loaded in fine.

      However for some reason my jquery animation is not working. I am using the jquery cycle plugin to rotate a banner area. I have the static HTML version that is identical to the wordpress version but the wordpress version is not working.

      Could the version at the end of the scripts be causing any kind of issue? Is there anyway to prevent those version numbers from being printed?

      Here's an example. Here is what the code looks like when the page has loaded in wordpress:


      <script type='text/javascript' src='http://localhost:8888/www.site.com/wp-content/themes/custom-theme/js/jquery.min.js?ver=3.0.1'></script>
      <script type='text/javascript' src='http://localhost:8888/www.site.com/wp-content/themes/custom-theme/js/jquery.cycle.all.2.74.js?ver=3.0.1'></script>

      <script type='text/javascript' src='http://localhost:8888/www.site.com/wp-content/themes/custom-theme/js/home_modules.js?ver=3.0.1'></script>




      ...and here is what it looks like in the static HTML version (which is functioning properly)


      <script type="text/javascript" src="js/jquery.min.js"></script>
      <script type="text/javascript" src="js/jquery.cycle.all.2.74.js"></script>
      <script type="text/javascript" src="js/home_modules.js"></script>



      Could the ?ver=3.0.1' be causing an error? Can that be turned off?

  • avatar
    Last edited:
    08/28/10
    9:07pm
    West Coast Design Co. says:

    Hey Five Squared,

    Turn off each plug-in one by one … and check your source, swear its probably a plug-in, I had a similar issue with Gravity Forms; http://wcdco.info/a6

    Cheers,

    Previous versions of this answer: 08/28/10 at 9:07pm

    • 08/28/10 9:07pm

      WP Answers says:

      Thanks for the info but I don't have any plugins at all installed.

  • avatar
    Last edited:
    08/28/10
    9:08pm
    Mike Truese says:

    flashingcursor has the right answer.

  • avatar
    Last edited:
    08/28/10
    10:36pm
    Bingu Zhong says:

    Add init function to your plugin:


    function init_THEME_scripts() {
    wp_deregister_script( 'jquery' );

    wp_register_script( 'jquery', THEME_JS .'/jquery.min.js');

    }
    add_action('init', 'my_init_method');

    function THEME_scripts() {

    wp_enqueue_script( 'jquery', THEME_JS .'/jquery.min.js', array('jquery'));

    wp_enqueue_script( 'jquery-accordion', THEME_JS .'/jquery.cycle.all.2.74.js', array('jquery'));

    wp_enqueue_script( 'cufon', THEME_JS .'/cufon.js', array('jquery'));

    wp_enqueue_script( 'cufon-fonts', THEME_JS .'/cufon-fonts.js', array('jquery'));

    wp_enqueue_script( 'cufon-settings', THEME_JS .'/cufon-settings.js', array('jquery'));

    wp_enqueue_script( 'THEME-custom', THEME_JS .'/home_modules.js', array('jquery'));

    }



    add_action('wp_print_scripts', 'THEME_scripts');


    you can check the function reference for more infomation.

    Previous versions of this answer: 08/28/10 at 10:36pm

This question has expired.





Current status of this question: Completed