0

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.

1 Answer 1

1

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' );
}
4
  • where do I do this?
    – Svish
    Commented May 28, 2011 at 22:54
  • In your theme's functions.php Commented May 28, 2011 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
    Commented May 29, 2011 at 2:27
  • I have updated my answer. Commented May 29, 2011 at 4:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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