Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I use the default TwentyTen theme and I have made a child theme with some CSS adjustments, and that's pretty much it.

Now I'd like to do two things

  • Make the theme load the latest jQuery, and to load it using the Google CDN.
  • Add a javascript file which would be loaded on every page.

What's the best way to do that? I'm a total WordPress newb, so don't really know my way around.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Here you go.

add_action('init', 'register_custom_jquery');
function register_custom_jquery() {
    wp_deregister_script('jquery');
    wp_register_script(
        'jquery', 
        'https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js', 
        array(), 
        '1.6.1'
    );

    wp_register_script(
        'my-custom-script', 
        'http://example.com/js/script.js', 
        array(), 
        '1.0'
    );
}

add_action('wp_enqueue_scripts', 'add_js_to_page');
function add_js_to_page() {
    wp_enqueue_script( 'jquery' );

    wp_enqueue_script( 'my-custom-script' );
}
share|improve this answer
    
where do I do this? –  Svish May 28 '11 at 22:54
    
In your theme's functions.php –  Hameedullah Khan May 28 '11 at 23:52
    
Aha. Could you just show how you would enqueue a custom script as well? Just want to be sure I get it right... –  Svish May 29 '11 at 2:27
    
I have updated my answer. –  Hameedullah Khan May 29 '11 at 4:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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