Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

i'm creating a wordpress theme and i am utilizing some scripts that use jQuery. It was working fine, until i enabled a particular plugin, named 'Paid Downloads'.

This actually made all of jquery dependencies not working anymore. So, i am thinking, that maybe i am doing something wrong. For instance, i am using prettyPhoto and initializing it like :

/* Pretty Photo */
    wp_register_style('pretty-photo-css', LIBRARIES_URI . "prettyPhoto/css/prettyPhoto.css");
    wp_enqueue_style('pretty-photo-css'); 
    wp_register_script('jquery-pretty-photo', LIBRARIES_URI . "prettyPhoto/js/jquery.prettyPhoto.js");
    wp_enqueue_script('jquery-pretty-photo', array('jquery-my'));

jquery.prettyPhoto.js is the actual prettyPhoto file and i have just added these few lines in the end of that file, in order to trigger the prettyPhoto effect :

jQuery.noConflict()

jQuery(function(){
  jQuery("a[rel^='prettyPhoto']").prettyPhoto();
});

JQuery is enqueued like :

    wp_register_script('jquery-my', "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js");
    wp_enqueue_script('jquery-my');

As i mentioned, this used to work before enabling the 'Paid Downloads' plugin. I am wondering. Am i doing something wrong ? When the plugin is enabled, i get errors like that in Chrome javascript console :

Uncaught TypeError: Object [object Object] has no method 'prettyPhoto'

It seems that there is a conflict because the plugin adds jquery for its own purpose ? Any ideas ?

share|improve this question
    
How do you enqueue jQuery in your theme? –  Mamaduka Sep 2 '11 at 12:10
    
edited my answer to reply your question –  SpyrosP Sep 2 '11 at 12:44

2 Answers 2

up vote 3 down vote accepted

Try and call method `prettyPhoto' when DOM is ready, replace your code:

jQuery.noConflict()

jQuery(function(){
  jQuery("a[rel^='prettyPhoto']").prettyPhoto();
});

with this:

jQuery(document).ready(function($) {
    $("a[rel^='prettyPhoto']").prettyPhoto();
});

Also 'Paid Downloads' plugins enqueues latest version of jQuery used by WordPress it's 1.6.1, it would be better if you register same version of jQuery from Google-CDN as WordPress does

share|improve this answer
    
+1 on $ vs. noConflict(); (where later is def. missing the trailing ;), but I wouldn't recommend registering jQuery from Google-CDN. Yes, it saves some server load, but def. increases loading time - Google even got a small delay before serving the reqeusted file(s). –  kaiser Sep 2 '11 at 13:22
    
Thanks, I don't like registering jQuery from Google-CDN either, but when someone does, it's better to register right version. I also like Codex approach to use plugin called Use Google Libraries –  Mamaduka Sep 2 '11 at 13:32
    
This seems to be working thanx :) I have to try it on a combination with the other plugins as well, but the prettyphoto error does not happen now, so i guess it's fine. –  SpyrosP Sep 2 '11 at 14:12
    
@Mamaduka You can change the Codex everytime. Just add or remove what you think is right. No once cares :) Btw: Hard to register the right version. Afaik you really have to know the exact path of the right version to not run into timeouts and else. –  kaiser Sep 2 '11 at 16:19

We can use like this way. Its little different. So its working separately.

var $jscript = jQuery.noConflict();
$jscript(document).ready(function(){
   $jscript("a[rel^='prettyPhoto']").prettyPhoto();
});
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.