WordPress.org

Support

Support » How-To and Troubleshooting » wp_deregister_script mystery

wp_deregister_script mystery

  • Hi all – my dropdown menus in the WordPress admin weren’t working, and I’ve isolated it to this code, placed in my functions.php:

    function my_functions_init_booktrib() {
    wp_deregister_script(‘jquery’);
    }
    add_action( ‘init’, ‘my_functions_init_booktrib’ );

    Can anyone explain why? I want to use Google’s version of jQuery, not WP’s, so I’d like to keep this code… thanks. (:

Viewing 11 replies - 1 through 11 (of 11 total)
  • Another weird thing I just noticed – the widget areas show up in the admin section, but the widgets that are in each section (as shown on the front end) don’t display. Any ideas here?

    If you want to use Google’s version of jQuery then you must deregister the jQuery included with WP and register the Google’s version of jQuery.

    <?php
    function my_functions_init_booktrib() {
        wp_deregister_script( 'jquery' );
        wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js');
    }    
    
    add_action('init', 'my_functions_init_booktrib');
    ?>

    Hi Reuben – thanks for the response. Is there some reason I can’t just include the script by hand, rather than using wp_register_script? That’s what I’m currently doing..

    You mean like this? or something else?

    <?php
     function jtest(){
       echo '<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>';
     }
     add_action( 'admin_head', 'jtest' );
    ?>

    note: the previous method is a good practice.

    Oh, literally just including this in header.php:

    <script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js”></script>

    Is there any way you can think of that this would have something to with why wp_deregister_script is breaking my dropdowns in the admin?

    umm…I’m confused.. Do you want jQuery on front end? if so you don’t need wp_derigster_script since you are not using wp_enqueue_script and yes you include that in header.php of the theme you are using.

    Well, I didn’t want to load multiple copies of jQuery. I’m loading my own from Google, so I deregistered the script so that plugins added later will use the Google version of jQuery and not WP’s.

    Oh, dur… maybe this is because those drop-downs in the back end use jQuery and it doesn’t load my version of jQuery from header.php…

    so I deregistered the script so that plugins added later will use the Google version of jQuery and not WP’s.

    For this you gotta register Google’s version of jQuery else it won’t work.

    Hmm, okay.. thanks!

    Hi KatieBen, I think what you need to do if you’re deregistering those is put your de-registration in a conditional like this:

    if ( !is_admin() ) {
        wp_deregister_script( 'jquery' );
    }

    Hope that helps if you haven’t already figured that out 😉

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘wp_deregister_script mystery’ is closed to new replies.