Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

WordPress WordPress Theme Development Working with CSS and JS in WordPress Themes Working with CSS and JS in WordPress Themes

Christian Melo
Christian Melo
299 Points

can i load js like: rws_enqueue_script ('https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min',true);

I think it is wp not rws. Yes you can include like this but using wordpress one will reduce page load.

Christian Melo
Christian Melo
299 Points

Thank You Ashish, the rws its just my initials to name the function and it it's working, thank you bro...

1 Answer

Hi Christian,

You would not need to include jQuery as it is default in WordPress.

I have put two examples below of how to use the wp_enqueue_scripts hook.

<?php

//* Enqueue Scripts and Styles
add_action( 'wp_enqueue_scripts', 'sample_enqueue_scripts_styles' );
function sample_enqueue_scripts_styles() {

        // Using a CDN or URL you would link like this.
    wp_enqueue_style( 'google-fonts', '//fonts.googleapis.com/css?family=Source+Sans+Pro:400,600,700';

        // To link to a file inside your theme directory you would do the following.
        // NOTE: Look at the - array('jquery') - you are saying that this script relied on jQuery to be loaded.
    wp_enqueue_script( 'sample-js', get_stylesheet_directory_uri() . '/js/sample.js', array( 'jquery' ), '1.0.0', true );

}

Take a look at the notes on this Codex page about wp_enqueue_script.

Hope this helps

Craig :)