Add .js Files To Child Theme
Load a Script from a Child Theme without any dependencies
- Add a js directory to Child Theme
Something like: urbannews-child/js/ - Add js files.
For example: urbannews-child/js/cactus-themes.js - Add this code segment with the structure as follows in urbannews-child/functions.php file to load a Script from a Child Theme
add_action( 'wp_enqueue_scripts', 'cactusthemes_child_add_scripts' );
/**
* Register and enqueue a script that does not depend on a JavaScript library.
*/
function cactusthemes_child_add_scripts() {
wp_register_script(
'cactusthemes-child',
get_stylesheet_directory_uri() . '/js/cactus-themes.js',
false,
'1.0',
true
);
wp_enqueue_script( 'cactusthemes-child' );
}
?>