HomeInternetWordPressChange the Source of jQuery in WordPress

Change the Source of jQuery in WordPress

Many reasons exist for picking a specific source for jQuery. One frequent example is the ability to host jQuery in a cloud or cdn environment. Insert the following function to pick where jQuery in hosted in your WordPress installation.

For many reasons, the fact that WP now comes preloaded with the entire jQuery library is awesome. However, many developers will feel more comfortable choosing where the library resides. Here is how to use your own hosted jQuery library instead of the default WP one.

We are going to edit the functions.php file through the WP Admin. Alternatively, you can perform this by simply editing the functions.php file in your current theme.

1 Navigate to Appearance – Editor

Wordpres Appearance Editor

2 On the right will be a list of all the current files in your theme being used on WordPress. Located your functions.php file and click on it to open it.

Wordpress Functions.php editor

3 We need to take off the current jQuery that is registered with WordPress, register ours, then re-add the file to the theme. So simply cut and paste the code into your WordPress functions.php file below:


function add_scripts() {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', 'http://code.jquery.com/jquery-1.7.1.min.js');
wp_enqueue_script( 'jquery' );
}
add_action('wp_enqueue_scripts', 'add_scripts');

Please note that in the 3rd line of code we use the jquery.com hosted library. You can change that link with an exact link to wherever you have it hosted.

4 Hit update file to save the changes.

5Now you have your own hosted solution of the jQuery library in WP. This allows you to run nonstandard versions of jQuery or host the library in a cdn to improve your load times.

Chris Luongo
Chris Luongo
Chris is a self-taught web designer and developer out of Atlanta, GA. This geek enjoys coffee, cold brews, bike riding, and twisting any form of tech into submission.
RELATED ARTICLES

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -

Most Popular

Recent Comments

Cleveland Furia on How to Clear Google Activity
Sid Wohlfarth on How to Clear Google Activity
Riley Magsayo on How to Clear Google Activity
สมัครรับเครดิตฟรี ทันที on How to improve Remote Desktop Protocol Performance
Neal Wangstad on How to Clear Google Activity
Slavcho Andov on How to install Ubuntu
Slavcho Andov on How to fix bad sectors
Sheraz Ali on How to Backup Android