wp_enqueue_script function so that we end up with the following: [code language="php"]<?php wp_enqueue_script("jquery"); ?> <?php wp_head(); ?>[/code] What this does is includes the Wordpress instance of jQuery however it is arguable about the efficiency of this method over loading it direct from Google servers since if everyone used this method users would" />

Silence isn't an absence of noise. It's a quality of mind.

Adding jQuery to a custom Wordpress theme

Posted in   Wordpress
I have been doing a little bit of Wordpress work recently and as a result I have been working on custom themes for Wordpress. In one particular theme I required that jQuery be loaded into the template and stumbled across the following wp_enqueue_script function built into wordpress. The function essentially adds a safe method of including scripts in Wordpress generated pages. Usage: I first needed to locate the following line in my head.php file: [code language="php"]<?php wp_head(); ?>[/code] Then before the call to this function I can add my call to the wp_enqueue_script function so that we end up with the following: [code language="php"]<?php wp_enqueue_script("jquery"); ?> <?php wp_head(); ?>[/code] What this does is includes the Wordpress instance of jQuery however it is arguable about the efficiency of this method over loading it direct from Google servers since if everyone used this method users would not need to take the hit downloading the file as there would be a greater chance of the file aready being in their cache. It is beyond the scope of this post to go into more detail on this however if you are interested in reading more you may want to swing by Encosia and read 3 reasons why you should let Google host jQuery for you. If you want to opt for this method you can simply amend the above example as follows: [code language="php"]<?php  wp_deregister_script('jquery');  wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js', false, '1.3.2');  wp_enqueue_script('jquery'); ?> <?php wp_head(); ?>[/code]

comments powered by Disqus