If you want to load a script or stylesheet from within a child theme in WordPress, you must use get_stylesheet_directory_uri()
in your path to the file, otherwise WordPress will look in the parent theme’s directory.
Load JavaScript or CSS file from a WordPress child theme
WordPress
// PHP
// Load custom script from child theme
function guyPrimavera_script_from_child_theme() {
wp_enqueue_script(
'my_script', // Script name
get_stylesheet_directory_uri() . '/js/my_script.js', // Script path (note the 'get_stylesheet_directory_uri')
array( 'jquery' ) // Dependencies
);
}
add_action( 'wp_enqueue_scripts', 'guyPrimavera_script_from_child_theme' ); // Call your function
Paste this snippet into your theme's functions.php or in a WordPress plugin.