Skip Navigation

[Resolved] conflict with jQuery based javascript

This thread is resolved. Here is a description of the problem and solution.

Problem: Several jQuery plugins that worked before activating Toolset plugins are no longer working.

Solution: Ensure the theme is enqueueing jQuery using WordPress standards and best practices.

Relevant Documentation:
https://codex.wordpress.org/Theme_Development

This support ticket is created 7 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by simonG-9 7 years ago.

Assisted by: Christian Cox.

Author
Posts
#595321

I am trying to: use Types, Views, Layouts and Maps with my site.

Link to a page where the issue can be seen: hidden link

I expected to see:

Instead, I got: a problem when activating Layouts or Views. The menu, using a SuperFish based script, loses it's animation and drop-down sub menus. A slider script and div height managing script on the front page also stop working.

Both scripts are loaded by the sites theme. I corrected the use of "$" to "jQuery" in these scripts as this showed up as a problem but this didn't solve the issue. I deactivated other plugins to rule those out and still experience the issue.

#595418

Hi, can you share some information about how your custom theme enqueues jQuery and the other jQuery plugin scripts in the header?

#595627

Hi Christian, currently jQuery and other jQuery scripts in the header are written in within the theme template(s).

#595709

For the best results with Toolset, you should follow WordPress best practices for theme development. See here:
https://codex.wordpress.org/Theme_Development

WordPress encourages you to use wp_enqueue_script() to add scripts in your theme for this very reason. If you do not enqueue scripts, other plugins do not know that your theme is already loading jQuery. So if those other plugins require jQuery, they will enqueue it (following best practices). If this happens after your jQuery plugins are loaded and added to the jQuery object by your theme, they will be lost.

When you enqueue a script, WordPress knows that only one 'jquery' script should be added to the page. This prevents more than one jQuery script from being loaded into the same jQuery object, so your extensions will not be overwritten. More info about best practices to enqueue scripts:
https://developer.wordpress.org/reference/functions/wp_enqueue_script/

#595737

Hi Christian, yes it does seem the theme isn't following best practice. I will try moving the script loading as suggested and hopefully that will resolve the issue. I will mark this issue resolved in the mean time, thanks for the advice.