0

I've inherited a site using the following in functions.php:

if ( ! function_exists( 'foundation_assets' ) ) :

function foundation_assets() {

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

    wp_enqueue_script( 'new-slider', get_template_directory_uri() . '/scripts/new.Slider.js', array(), NULL, true );  
}

add_action( 'wp_enqueue_scripts', 'foundation_assets' );

endif;

If I prevent this function from running, other plugins load additional scripts correctly.

Has the original theme developer done something bad here? Is it possible that other plugins depending on jQuery will break if it is deregistered in this way?

3
  • It's a bad practice deregistering jQuery. There are many scripts in admin panel are jQuery dependent. (see the need dependency part) If your script is not working see the noConflict wrapper is correctly used or not. Commented Mar 19, 2015 at 10:07
  • If you read the code, it is only being deregistered on the front end
    – codecowboy
    Commented Mar 19, 2015 at 10:08
  • 2
    If you deregister or dequeue jquery, you will break all scripts dependant on jquery. I really don't see the point why you would like to deregister jquery. It is like cutting of your nose to spite your face :-) Commented Mar 19, 2015 at 10:12

1 Answer 1

1

I think you are missing the point here about dependency. If the dependency parameter has been set when registering or enqueueing a style or script, that style or script will wait in queue for the style or script it is dependent on to load. This particular script or style will not load until the script or style it is dependant on is fully loaded.

Now, if you deregister that script or style that others are dependent on, it is obvious that that particular script or style will never load, which in turn will mean that any script or style that is dependent on that particular style or script will always stay in queue and will never load. It is the same waiting for a bus to take you to your destination, but you will never be able to reach your destination with that particular bus as that specific bus has been cancelled indefinitely

I'm not sure why the original author has done that, but I really see no point in deregistering jquery as this breaks so many visual representation and in some cases, functionality of the site.

2
  • I think the original author wanted to use a newer version of jQuery so deregistered it and put a standard script tag loading a newer version in the theme's header. However, other plugins using the correct way to enqueue scripts presumably do not work because they are using the WordPress dependency system as you describe.
    – codecowboy
    Commented Mar 19, 2015 at 11:40
  • Ha! Might be. That is one big reason why you should never load scripts and style directly in the header. Always use wp_enqueue_scripts correctly, and you will never have future problems :-) Enjoy Commented Mar 19, 2015 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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