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 have this part of code which loads custom version of jquery

        wp_deregister_script('jquery');
        wp_register_script('jquery', ("http://code.jquery.com/jquery-latest.min.js"), false, '');
        wp_enqueue_script('jquery');

Everything works fine but if i open the media upload manager which is loaded by this code

    wp_enqueue_script('media-upload');
    wp_enqueue_script('thickbox');
    wp_enqueue_style('thickbox');

and triggered by this

                <script language="JavaScript">
                    jQuery(document).ready(function() {
                    jQuery('#upload_image_button').click(function() {
                    formfield = jQuery('#upload_image').attr('name');
                    tb_show('', 'media-upload.php?type=image&TB_iframe=true');
                    return false;
                    });

                    window.send_to_editor = function(html) {
                    imgurl = jQuery('img',html).attr('src');
                    jQuery('#upload_image').val(imgurl);
                    tb_remove();
                    }

                    });
                </script>
                    <label for="upload_image">
                        <input id="upload_image" type="text" size="36" name="upload_image" value="<?php  ?>" />
                        <input id="upload_image_button" type="button" value="Upload Image" />
                        <br />Enter an URL or upload an image for the banner.
                    </label>

The lightbox opens and displays all options, but when i choose "Upload Image" or if i go to media library and select an image from there nothing happens.

If i remove the custom jquery the media uploader works fine. But then the jquery ui code i have is not working, although i am loading the jquery-ui script, so i have to load my custom latest version of jquery.

Is there any solution so both media-upload and jquery-ui are working on the same page in the plugins admin panel?

share|improve this question
    
Fix the custom jQuery code? –  toscho Jul 19 '12 at 12:48
    
What do you mean?By custom version i mean(as shown in the code) that i am loading the latest version of jQuery. I do not have any jQuery errors in my code. –  Sport Billy Jul 19 '12 at 12:55
1  
I mean the jQuery UI code you have written and that relies on the remote jQuery. Rewrite it until you can use the regular jQuery from WordPress. –  toscho Jul 19 '12 at 12:58

1 Answer 1

A lot of people think it's a bad practice to deregister/reregister jQuery, despite the performance improvements c/o a CDNed version (and if you're going for a CDN, I see Google's version more often than jQuery's). However, if you're going to do that, you really should only do that on the front-end only so at least the admin can correctly assume that the current WP-preloaded jQuery version is being used.

So switch your script to this and I suspect your problems probably will end:

function my_custom_scripts() {
    if( !is_admin() ) {
        wp_deregister_script('jquery');
        wp_register_script('jquery', ("http://code.jquery.com/jquery-latest.min.js"), false, '');
        wp_enqueue_script('jquery');
    }
}
add_action( 'wp_enqueue_scripts', 'my_custom_scripts' );
share|improve this answer
    
Hey thanks, already tried that and as i say to my question when i remove the custom jquery version from admin the media-upload works fine, but then the jquery ui and other jquery scripts i am loading break down. Those scripts are loaded in the header and it looks like jquery version of wordpress is loaded after them. –  Sport Billy Jul 20 '12 at 8:48
1  
If it's an issue of loading order, you just need to specify the 'jquery' handle for the $deps argument of wp_enqueue_script() in your jquery-ui and custom scripts. –  mrwweb Jul 20 '12 at 22:12

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.