1

I'm looking after a Wordpress install that makes use of a plugin that deregisters jQuery and replaces it with it's own ancient version. I'm aware of why loading your own jQuery is irresponsible and would like to use the version of jQuery bundled with Wordpress. I'm currently deregistering the plugin's version of jQuery and enqueuing the Wordpress version. However my approach makes some assumptions about the location and version of jQuery. Is there a better way to do this and ensure things don't break when Wordpress is updated?

wp_deregister_script( 'jquery' );
wp_enqueue_script( 'jquery', '/wp-includes/js/jquery/jquery.js', array(), '1.10.2', false ); 
2
  • 3
    Use includes_url( 'js/jquery/jquery.js' ) Mar 17, 2014 at 10:48
  • 1
    Might be worth shooting a note to the plugin author too. Mar 17, 2014 at 15:55

1 Answer 1

1

I think you can just use:

wp_enqueue_script( 'jquery' );

And WordPress will know to use the included one.

Edit:

You can use:

wp_enqueue_script( 'jquery-core' );

Assuming that hasn't also been deregistered by another script. I guess this could run the risk of allowing a plugin to register 'jquery' and for 2 versions of jquery to be loaded, though. Keep an eye out!

7
  • I don't think it works. Dylan has de-registered jquery hook first and didn't register any hook. Therefore simply en-queuing the hook will throw an error.
    – sri
    Mar 17, 2014 at 9:38
  • Hmm, you're quite right.
    – James Kemp
    Mar 17, 2014 at 10:05
  • I wonder whether using 'jquery-core' would work? github.com/WordPress/WordPress/blob/…
    – James Kemp
    Mar 17, 2014 at 10:06
  • @James Kemp Thanks, that works. Please edit your answer and I'll accept it. Cheers, Dylan.
    – Dylan
    Mar 17, 2014 at 10:29
  • Edited, also added a potential issue using that method.
    – James Kemp
    Mar 17, 2014 at 10:36

Your Answer

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

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