Well, the title is pretty explanatory…
I am building a custom theme where all the fancy jQuery stuff (sliders, galleries, toggle, tooltips, etc) are manually added to head of the document, and of course, I call jQuery manually too. I prefer to work on this way instead of running wordpress plugins.
But the problem is…
There is one single plugin out there that I am not able to live without: WP-POLLS.
And what happens? As soon as I start this plugin, it calls jQuery again! And all my other stuff gets broken.
I can see 3 ways:
1 – Editing the wp-polls PHP file and remove this its jQuery calling/including
2 – Editing the wp-polls PHP file and try to insert a verification to see if jQuery is already loaded in the lines where it (re)loads/(re)includes the jQuery
3 – Learn the correct way to perform the jQuery including for my stuff that will not conflict with WP-Polls.
Any ideas, guys?
Thanks sooo much.
C.
EDIT
I think I found the way to solve the issue.
Maybe it is not the professional method, but apparently it worked!
My WP header.php was:
<html>
<head>
// Library
jQuery library including
// My own manual fancy stuff
Slider
Carousel
Tooltip
Etc
// WP Head stuff
wp_head();
</head>
Then, I changed to:
<html>
<head>
// WP Head stuff
wp_head();
// Library (Removed OUT!)
// jQuery library including
// My own manual fancy stuff
Slider
Carousel
Tooltip
Etc
</head>
And added, to my theme functions.php file the following:
function load_my_scripts() {
if (!is_admin()) {
wp_deregister_script( 'jquery' );
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js');
wp_enqueue_script('jquery');
}
} add_action('init', 'load_my_scripts');
Now, WP-POLLS and all my fancy stuff are working fine.
But, I am not sure about…
Is there any recommendation about including wp_head() in the top of the HTML ? If I remember well it should be ever included right before the closing tag.
And, in the wp_register_script, it is better to call a local jQuery library or the google one?
Thanks to all people who are watching this thread!
Regards,
C
The best solution is to add jQuery using wp_enqueue_script() – like you did in your edit – instead of adding it manually. When using wp_enqueue_script(), no matter how many times it is called from plugins or the theme, it will only output each particular script once. This prevents problems like jQuery being included twice.
As for the placement of wp_head():
Finally, I can’t give a general answer to whether it’s better to use the local jQuery library or the one from Google, but in your case, I would recommend sticking with the local one.