Using Google-Hosted JavaScript Libraries with WordPress

by Simon. Average Reading Time: about a minute.

With the announcement that Google will be including page loading times as part of it’s SERPs ranking algorithm, it has become increasingly important to optimise your use of 3rd-party libraries such as jQuery.

If you want — and this is the default setting for WordPress, themes and plugins — you can just download jQuery, put it on your server and link to it from your header.php file in the <head> section.

However, it is better to use the proper wp_register_script() function, which can be achieved in your functions.php file:

if( !is_admin() ) {

The reason we use the wp_register_script() is to ensure that WordPress and its themes and plugins are aware that the script has been loaded and therefore not to load an additional copy.

I have also used the is_admin() function to prevent conflict and therefore errors, in the WordPress administrator.

Of course, this method is not only restricted to jQuery, you can do the same for other popular JavaScript frameworks such as Mootools.

Further information on the wp_enqueue_script can be found on the WordPress Codex.

This article has been tagged

, , ,

Other articles I recommend

jQuery 1.2 API Reference

Among the plethora of JavaScript libraries to have been released, few have been recognised to be as effective as jQuery. This lightweight library has been the subject of different discussions since it was launched in 2006. Basically, jQuery has the ability to flawlessly string together JavaScript together with HTML. Because of its effectiveness, there have different types of lightweight applications and plug-ins launched using jQuery. Ajax based websites that offers simple interface would virtually work together using jQuery’s simple interface.

Using jQuery Auto-Complete with ColdFusion

Creating an autocomplete form field historically has not been a trivial matter and would require an indepth knowledge of JavaScript and CSS. However, the task is made far more simple when using one of the many freely-available JavaScript libraries. In this post I will show you how to implement the jQuery Autocomplete created by Dylan Verheul.

Secure Your WordPress Installation

Security is often an overlooked aspect of blogging, but a few minutes making sure things are secure can save you hours and hours of ‘fixing’ if someone decides to mess with your site.

  • Thanks a lot for that tip. Ecpecially for a wordpress greenhorn like me it is very helfpfully. I will achieve it in the functions file. I hope it works as mentioned above.