How to enqueue custom JS script to WordPress functions.php

Last updated on

Open functions.php in your WordPress themes folder, usually located in /wp-content/themes/{theme_name}/

Add the following code to the end of functions.php

function custom_scripts() {
	wp_register_script( 'owl', get_template_directory_uri() . '/assets/js/owl.carousel.js' );
	wp_enqueue_script('owl');
}
add_action( 'wp_enqueue_scripts', 'custom_scripts' );

In the above example we are enqueuing the Owl Carousel script.

Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.

p.s. I increased my AdSense revenue by 200% using AI 🤖. Read my Ezoic review to find out how.

Leave a reply

Your email address will not be published.