I want to call a jQuery from my functions.php
in WordPress.
I’m using Divi Theme. When I add the script directly into Divi theme it works. But I want to add it to the functions.php
form my child theme and this is where the problem start.
Functions.php
function coolbanner_enqueue() {
wp_enqueue_script( 'custom-scripts', get_stylesheet_directory_uri() . '/js/coolbanner.js', array( 'jquery' ));
}
add_action( 'wp_enqueue_scripts', 'coolbanner_enqueue' );
Script:
jQuery(document).ready(function(){
jQuery('#cta-section').waypoint(function() {
jQuery('#cta-section').toggleClass('animate-cta');
}, {offset: '80%'});
});
Can somebody point out what I’m doing wrong?
2
Answers
Solution:
Seems like you’re missing the jQuery Waypoint JS file
Try enqueueing the jquery waypoint js file BEFORE using your custom script
you can find the jquery waypoint github repo here…
https://github.com/imakewebthings/waypoints
Additionally the url I used below is from a cdn which you can find here:
https://cdnjs.com/libraries/waypoints
if you feel more comfortable using the github’s url
then just substitute the cdn url with the following…
https://raw.githubusercontent.com/imakewebthings/waypoints/master/lib/jquery.waypoints.min.js