Breaks jQuery
-
@jonazu – Thanks, but there really is not much to work with here; and, it would probably be much better to create a support topic to try to sort out the problems you are seeing on your site.
– Cais.
@jonazu – I’d second @photocrati on this. Obviously NextGEN Gallery works well alongside most WordPress plugins and doesn’t cause issues with jquery for most users. Can you provide any details on the specific issues you were having, including which plugins you saw a conflict with?
I din’t expect replies. I’m positively surprised. Thanks.
So if you make the effort to reply, I make the effort to explain the problem. (And maybe we find a solution?) And I have to admit I was a bit angry by the time I did the review as I lost some time figuring out why this happend. Sorry for that.Anyway, I use FoundationPress which enques it’s own jQuery in functions.php:
wp_deregister_script( 'jquery' ); wp_register_script( 'jquery', get_template_directory_uri() . '/js/jquery/dist/jquery.min.js', array(), '1.0.0', false ); wp_enqueue_script( 'jquery' );The HTML looks like this:
<script type='text/javascript' src='[url to theme folder]/js/jquery/dist/jquery.min.js'></script>I have other jQuery dependent code which works well with this setting. The only plugin which uses jQuery (I suppose) is Contact Form 7 for the AJAX success alert once I’ve sent the form.
After activation of NextGEN Gallery the code looks like this:
<script type='text/javascript' src='[domain]/wp-includes/js/jquery/jquery.js'></script> <script type='text/javascript' src='[domain]/wp-includes/js/jquery/jquery-migrate.min.js'></script>The custom jQuery is gone. And my custom code isn’t working anymore because of this JavaScript error:
TypeError: $ is not a functionWhich is caused by this simple jQuery check:
$(document).ready(function () {Contact Form 7 is working, though.
I think I could figure out some workaround, but I want to use the jQuery delivered by FoundationPress. And actually I don’t understand why NextGEN overrides my custom jQuery?
@jonazu –
I see that FoundationPress is enqueueing it’s bundled version of jQuery but it is also enqueueing it as version 1.0.0 when the current bundled version appears to be 2.1.1 (see https://github.com/olefredrik/FoundationPress/blob/master/js/jquery/dist/jquery.js)
NextGEN Gallery expects and enqueues the version of jQuery bundled with WordPress (this is to ensure the most backward compatible solution, especially since jQuery 2.1.1 for instance does not support Internet Explorer version before 9).
As it is, since NextGEN Gallery is enqueueing a later version than what FoundationPress is enqueueing (by virtue of the WordPress code not the actual jQuery version) the NextGEN Gallery enqueue statement is taken as the authority. In most cases, if you are enqueueing a jQuery version of the same or higher version than what NextGEN Gallery enqueues (the WordPress bundled version) then the external/higher version is used instead.
We have not tested NextGEN Gallery with jQuery versions higher than the WordPress bundled version at this time so I cannot say if there will be issues with using jQuery 2.x but I would go back to the FoundationPress author and ask them about their jQuery ensue statement as you have noted it above (or feel free to change the version parameter yourself to see if this corrects for the issues you are seeing).
Please let us know … and feel just as free to create a support ticket or send us a Bug Report (http://www.nextgen-gallery.com/report-bug/) if the issues persist so we can further review this.
Thanks!
– Cais.
I didn’t think of the version parameter. Thanks for pointing that out.
Unfortunately this didn’t solve it. My current version is the most recent 2.1.1.
So I was a bit curios how NextGEN is handling all this jQuery things and I found out that there is a fix_jquery function which is used with the wp_print_scripts. I citate the codex:
Since WordPress 3.3, wp_print_scripts should not be used to enqueue styles or scripts.
I commented the action
add_action('wp_print_scripts', array(&$this, 'fix_jquery'));and my code works now. I still have to test if NextGEN is working without errors. But anyhow shouldn’t you remove this line?
@jonazu – This is being reviewed … although the codex may recommend not using it, there are cases where it is still appropriate. We are reviewing this to see if our ideas on why we are using this hook still apply.
Thank you very much for this additional feedback.
– Cais.
@photocrati: Just a quick update on my current workaround: I ended up replacing $ with “jQuery”. Not very elegant but it works now. (Removing your wp_print_scripts hook gave me JS errors with fancybox.)
And btw: I bought the Plus Edition as I really like the functionality of the plugin and needed better templates. Maybe this speeds up the process with fixing the wp_print_scripts. 😉
The topic ‘Breaks jQuery’ is closed to new replies.