Add custom jQuery script to WordPress theme

How to add custom jQuery script to WordPress theme ?

Code for functions.php to add jQuery script from file to theme directory and js folder:

function add_js_for_theme() {
wp_enqueue_script( 'js-custom', get_stylesheet_directory_uri() . '/js/js-custom.js');
}

add_action( 'wp_enqueue_scripts', 'add_js_for_theme', 10 );

And jQuery script “js-custom.js” when website is loaded:

File location: “YourTheme/js/js-custom.js”

jQuery(document).ready(function(){

});

When jQuery is used for WordPress script must use jQuery instead of $ sign.

Advertisements
Add custom jQuery script to WordPress theme

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s