-
AuthorPosts
-
July 22, 2014 at 9:36 pm #294581
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.
July 23, 2014 at 12:01 am #294641Hi 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!
YigitJuly 23, 2014 at 12:19 am #294659Thank 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 ); }July 23, 2014 at 12:24 am #294664Hi!
Did you include the file inside a folder called “custom-js”? If not, please do so
Best regards,
YigitJuly 23, 2014 at 12:28 am #294671This reply has been marked as private.July 23, 2014 at 12:36 am #294677Hi!
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,
YigitJuly 23, 2014 at 12:39 am #294680That did it !!!! Thank you!
July 23, 2014 at 12:45 am #294682 -
AuthorPosts
- The topic ‘Adding custom jquery script to Child Theme’ is closed to new replies.
