$8
JQuery Conflict - Plugins messing things up
I'm working on my custom wordpress theme. I'm new to theme development but have learned tons thanks to everyone on this site.
I am running into an issue with jQuery. When my customers install their theme and then install a whole bunch of plugins, my default jQuery file being called in no longer gets called in. This is causing certain functionalities not to work properly.
Is there anything I can do to my jQuery file to make sure that no matter what plugins they install, it will not affect my jQuery funtionality?
Here is the code I am using to pull in the JQuery. I thought this prvents other instances of jQuery from loading in but I guess not.
Any help is greatly appreciated.
<?php wp_enqueue_script("jquery"); ?>
<?php wp_head(); ?>
<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/jquery-1.2.6.min.js"></script>
WP Answers | 04/23/10 at 12:48am
| Edit
(2) Possible Answers Submitted...
-

Last edited:
04/23/10
12:56amBuzu B says:you can add the call to your jquery directly in the header.php file. This file is always called so, it is pretty safe to include it there.
You can also include it in footer.php at the very end...Previous versions of this answer: 04/23/10 at 12:56am
- 04/23/10 12:57am
WP Answers says:Hi Buzu,
This is where it currently gets called. But when users install plugins it seems to take mine out and add in a different jquery file? I notice this because I compare the source code of the theme on their site, and the code on my site - 04/23/10 1:06am
Buzu B says:I see...
If the plugin is using another version of jquery, you might not be able to make it work. Even if you could add both files, one will always overwrite the other. The best solution would be to port your code so it works with the version of jquery the plugin uses, though I wouldn't recommend it if the version of jquery the plugin uses is older than the one you use. - 04/23/10 1:12am
WP Answers says:Hmm..Ok.
I'm surprised there is no way around this conflict. - 04/23/10 1:17am
Buzu B says:The thing is that at the end of every jQuery version, jquery does this:
window.jQuery = window.$ = jQuery;
So, even if you add both files, when jquery gets exposed to the global environment, it gets exposed on the same variable, so when the second jquery file gets loaded it will overwrite the first one. I have never actually tried this but I'm sure that is what will happen.
- 04/23/10 12:57am
-

Last edited:
04/23/10
1:34amMerne Asplund says:I ran into a similar issue. This seemed to work for me:
<?php
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');
?>
This should go in your themes function file.Previous versions of this answer: 04/23/10 at 1:14am | 04/23/10 at 1:17am
- 04/23/10 1:17am
WP Answers says:Hi,
Thank you for this. Which part of that code do I use? Should I get rid of what I currently have in my header.php? - 04/23/10 1:24am
WP Answers says:Thank you for this, but it doesn't seem to be doing anything.
Here is the situation. I have the exact theme theme running on 2 different servers. Everything works perfectly on one server because it does not have any conflicting plug-ins. On the other server they have a bunch of plug-ins and one or more of them are obviously conflicting.
When I view the source code, the verison of the site with the issues does not call in my javascript file, but instead, a few lines down another version of jQuery is being called.
Isn;t there something I can do, just as this plugin has done, that removes any other instance of jquery and inputs mine?
If not I compeltely understand. I'll just have to let my client know they have to lose their plugins. - 04/23/10 1:26am
Merne Asplund says:On second thought, you may just want to add 'wp_deregister_script( 'jquery' );' in place of your 'wp_enqueue_script("jquery");'. It seems you are adding jquery more than once here in two different ways. Also, we will do this after wp_head() to make sure the jquery loaded is your version.
so to recap you should have:
<?php wp_head(); ?>
<?php wp_deregister_script("jquery"); ?>
<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/jquery-1.2.6.min.js"></script>
- 04/23/10 1:29am
WP Answers says:Thank you, but still no dice. There is no change at all. The code still renders just as before.
- 04/23/10 1:30am
Merne Asplund says:I must warn you that this may not work if a plugin is loading their jquery somewhere outside of the init or admin_head events.
- 04/23/10 1:34am
WP Answers says:This worked!
Sorry, but the client switched the theme in his back-end while I was making changes so I was making changes to the wrong theme.
This works perfectly:
<?php wp_head(); ?>
<?php wp_deregister_script("jquery"); ?>
<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/jquery-1.2.6.min.js"></script>
Thank you very much - I really appreciate it. - 04/23/10 1:34am
Merne Asplund says:Are you using plugins that are compatible with the current version of wordpress you are running?
- 04/23/10 1:35am
Merne Asplund says:nvm. your very welcome.
- 04/23/10 1:17am
This question has expired.
Current status of this question: Completed





