WordPress.org

Ready to get started?Download WordPress

Forums

wp_deregister_script mystery (12 posts)

  1. KatieBen
    Member
    Posted 3 years ago #

    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. (:

  2. KatieBen
    Member
    Posted 3 years ago #

    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?

  3. Reuben Gunday
    Member
    Posted 3 years ago #

    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');
    ?>
  4. KatieBen
    Member
    Posted 3 years ago #

    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..

  5. Reuben Gunday
    Member
    Posted 3 years ago #

    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.

  6. KatieBen
    Member
    Posted 3 years ago #

    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?

  7. Reuben Gunday
    Member
    Posted 3 years ago #

    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.

  8. KatieBen
    Member
    Posted 3 years ago #

    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.

  9. KatieBen
    Member
    Posted 3 years ago #

    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...

  10. Reuben Gunday
    Member
    Posted 3 years ago #

    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.

  11. KatieBen
    Member
    Posted 3 years ago #

    Hmm, okay.. thanks!

  12. 10sexyapples
    Member
    Posted 3 years ago #

    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 ;-)

Topic Closed

This topic has been closed to new replies.

About this Topic