Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Plugin causing Javascript failure WordPress

  • SOLVED

Using Event Espresso for event registration. This has happened before where this particular plugin make the site's javascript fail. For example, the home page slider doesn't work. I'm looking for someone to fix this. I had it done on a similar site last year, but have forgotten what they did.

Answers (5)

2011-10-10

Abdessamad Idrissi answers:

I see that you use jQuery from google; don't you think it is better to use the jquery integrated already by WordPress?
put this inside your theme's "functions.php"

function my_init() {
if (!is_admin()) {
wp_enqueue_script('jquery');
}
}
add_action('init', 'my_init');


Second thing is you are using the coda slider that is not meant for wordpress (which maybe creates conflict problems for you): why not use the [[LINK href="http://wordpress.org/extend/plugins/wp-coda-slider/"]]WordPress[[/LINK]] version?

If you do those steps and still the problem happens (which i doubt) then pm me ;)


Patrick MacAdams comments:

Using wp_enqueue was the solution when i had the same conflict with this plugin previously. (That site's url: http://www.scoopituplax.com). However, after adding the above to the theme's funcitons.php, nothing changed.

--The slider came with the theme I'm using, along with the library it's using.


Abdessamad Idrissi comments:

the errors are happening because of "jquery.coda-slider-2.0.js" it is not WordPress friendly; it uses the $ symbol as a shortcut to jQuery.. the problem is there's other scripts who use this $ too.. so they conflict!
There's two approaches to fix this: use the WordPress version of the coda slider or open "jquery.coda-slider-2.0.js" and replace all the $ symbols with jQuery (case sensitive)


Abdessamad Idrissi comments:

comparing your theme version to the original repro theme's demo page; I noticed the use of noConflict function by sugar fags (mfxAccordion) plugin.. can you disable that plugin and check again?


Patrick MacAdams comments:

replacing the $ worked. thanks!

2011-10-10

Luis Cordova answers:

go to google chrome, open site and check the error console @ Development Tools options, see which js causes the problem, then deactivate the plugin whose js is inserting it, and then work on the plugin js and then install back up. The js usually is a simple error conflicting for that use jquery no conflict mechanism http://www.google.com/#sclient=psy&hl=en&site=&q=jquery%20noconflict

That should do it.

So now that I checked the site:

The problem shows:

Uncaught TypeError: Property '$' of object [object DOMWindow] is not a function

@ harverstlacroste.com/wp-content/themes/repro/js/jquery.coda-slider-2.0.js:9

so is the problem I described. There is a plugin you have added to your clean theme that does not respect the convention and inserts jquery code without indicating there should be some care with conflicts. Thereby the solution is to add the noconflict to your plugin's code. The plugin can be easily discovered while deactivating one by one and checking if the error disappeared, this is at least 20 clicks away if you have 10 plugins or even less just refreshing.

Here is how you add the noConflict to the js file of your plugin

http://api.jquery.com/jQuery.noConflict/

this section here will explain you what is happening : http://codex.wordpress.org/Function_Reference/wp_enqueue_script
check the section jQuery noConflict wrappers

so you need to insert the noconflict directive as here:


<script type="text/javascript">
$.noConflict();
jQuery(document).ready(function($) {
// Code that uses jQuery's $ can follow here.
});
// Code that uses other library's $ can follow here.
</script>



Patrick MacAdams comments:

I know which plugin is causing the conflict, but I do not know how to: "add the noconflict to your plugin's code"


Luis Cordova comments:

Here is how you add the noConflict to the js file of your plugin

http://api.jquery.com/jQuery.noConflict/

this section here will explain you what is happening : http://codex.wordpress.org/Function_Reference/wp_enqueue_script
check the section jQuery noConflict wrappers

so you need to insert the noconflict directive as here:



<script type="text/javascript">

$.noConflict();

jQuery(document).ready(function($) {

// Code that uses jQuery's $ can follow here.

});

// Code that uses other library's $ can follow here.

</script>

2011-10-10

Hardeep Singh answers:

Please share site address.


Patrick MacAdams comments:

http://www.harvestlacrosse.com

2011-10-10

Jurre Hanema answers:

I am not entirely sure, but I think this snippet is causing the error:

<script type="text/javascript">
//<![CDATA[
var $j = jQuery.noConflict();
$j(window).load(function(){
$j('.sugar-faqs-wrap').mfxAccordion({
slideSpeed: 300,
singleOption: false
});
});
//]]>
</script>

Do you know where this comes from? Try removing the call to the noConflict()-function, like so:

<script type="text/javascript">
//<![CDATA[
jQuery(window).load(function(){
jQuery('.sugar-faqs-wrap').mfxAccordion({
slideSpeed: 300,
singleOption: false
});
});
//]]>
</script>


Calling jQuery.noConflict() should only be neccessary if you are planning on using another Javascript library which also uses the $. In this case however, it only creates the problem that the $ cannot be used anymore for jQuery which breaks the Coda Slider.


Patrick MacAdams comments:

It's not just the slider that is conflicting. You'll also notice on the "lessons" page that the Total Cost isn't populating either. Also, a cufon replacement is disable.

There are a dozen js files in the conflicting plugin (Event Espresso). I'm looking for someone to go in and fix the issue. I am a front-end designer. Let me know if someone is game & your rate.


Jurre Hanema comments:

As far as I can see, every page has the same error: $ is not a function.

Have you tried removing the call to noConflict() yet? I vaguely remember having exactly this issue with noConflict() quite a while back.

If that doesn't fix it, good luck with finding a developer! (I could do it, but sadly I don't have much time)

2011-10-10

designchemical answers:

The namespace isnt defined correctly for the coda slider. Change the coda slider file at repro/js/jquery.coda-slider-2.0.js for the code in the link below:

<a href="http://www.designchemical.com/lab/projects/jquery.coda-slider-2.0.js">http://www.designchemical.com/lab/projects/jquery.coda-slider-2.0.js</a>

The changes are to lines 7, 12 and 235