I need to add a jquery script to a Enfold child theme. Can you please tell me the best way so the Parent theme can be updated and not overwrite this script in the Child? I’d like the script available on all pages of the site. Any help is appreciated.
Hi klondike91!
Please go to Appearance > Editor and add following code to Functions.php file of your child theme
function add_custom_script(){
?>
<script>
PASTE YOUR CODE HERE
</script>
<?php
}
add_action('wp_footer', 'add_custom_script');
Cheers!
Yigit
Thank you! What if I wanted to include the js file jquery.enrollware.js that is needed to run the script? The file is located in the Child theme. I tried this, but it does not work. Any suggestions?
function add_my_script() {
wp_enqueue_script(
'enrollware-script', // name your script so that you can attach other scripts and de-register, etc.
get_stylesheet_directory_uri().'/custom-js/jquery.enrollware.js', // this is the location of your script file
array('jquery') // this array lists the scripts upon which your script depends
);
}
Hi!
Did you include the file inside a folder called “custom-js”? If not, please do so
Best regards,
Yigit
Hi!
Please add following line to right below the code you have added in Functions.php file
add_action( 'wp_enqueue_scripts', 'add_my_script' );
so it should be
function add_my_script() {
wp_enqueue_script(
'enrollware-script', // name your script so that you can attach other scripts and de-register, etc.
get_stylesheet_directory_uri().'/custom-js/jquery.enrollware.js', // this is the location of your script file
array('jquery') // this array lists the scripts upon which your script depends
);
}
add_action( 'wp_enqueue_scripts', 'add_my_script' );
Currently it is not being enqueued
Regards,
Yigit
That did it !!!! Thank you!