2

I run WordPress version 4.7.2. and it uses jQuery version 1.12. I need to update this version to a higher one,

i can use :

function sof_load_scripts() {
if ( !is_admin() ) {
wp_deregister_script('jquery');
wp_register_script('jquery', 'https://ajax.googleapis.com    /ajax/libs/jquery/1.8.2/jquery.min.js', '1.8.2', false);
wp_enqueue_script('jquery');
}
}
add_action( 'wp_enqueue_scripts', 'sof_load_scripts' );

but in the themeforest developers quide we have :

The default version of jQuery being used must never be deregistered. JavaScript and CSS files should never be loaded directly. Plugins should not attempt to load duplicate or alternate versions of files already included in WordPress Core, especially jQuery.

how can i update version of jquery ?

iranimij
  • 91
  • 10
  • Are you responsible for the whole site? That is an old version and worth upgrading – charlietfl Jul 17 '19 at 17:36
  • If you really, _really_ need to use a newer version of jQuery than the one that comes bundled with WordPress then what you're doing already is the right way to go. If you don't mind me asking, why do you need version 1.8.2? – cabrerahector Jul 17 '19 at 18:01
  • your function is ok as far as other plugins will not load different versions. – Obmerk Kronen Jul 17 '19 at 20:01

1 Answers1

2

Your function is actually ok if you really want to change the version sitewide.

Just another remark - note that you can use also 2 ( or more ) different versions together thanks to the jQuery noConflict mode and that way you could use the version you need on your specific plugin / theme and leave the defaults for the rest.

See more details here : Can I use multiple versions of jQuery on the same page?

Obmerk Kronen
  • 15,619
  • 16
  • 66
  • 105