Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #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.

    #294641

    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

    #294659

    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
        );
    }
    #294664

    Hi!

    Did you include the file inside a folder called “custom-js”? If not, please do so

    Best regards,
    Yigit

    #294671
    This reply has been marked as private.
    #294677

    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

    #294680

    That did it !!!! Thank you!

    #294682

    Hey!

    You are welcome, glad we could help :)

    Regards,
    Yigit

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Adding custom jquery script to Child Theme’ is closed to new replies.