Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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 :)