0

I'm developing a wordpress site and I need to trigger the user scroll in order to fire different events and hide/show some images, so Waypoints.js is perfect for it.

However I've tried different attempts to make it work with no results. I add it as a function on functions.php file, like this:

function waypoints_method() {
    wp_deregister_script('jquery');
    wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js", false, null);
    wp_enqueue_script('jquery');
    wp_enqueue_script('waypoints', get_stylesheet_directory_uri() . '/vendor/waypoints/lib/jquery.waypoints.min.js');
}
add_action( 'wp_enqueue_scripts', 'waypoints_method' );

And then in the javascript:

jQuery(document).ready(function($) {
     $('.waypoint').waypoint(function() {
            alert('You have scrolled to my waypoint.');
        });
}

The only thing I get it is to console.log when resizing the browser. So, what I need to do in order to make it work? Or, there is any alternative to Waypoints.js that I could use?

Thanks!

4
  • WordPress loads jQuery in "noconflict" mode, so you can't use $() unless it's inside an IIFE. Try changing your code to use jQuery('.waypoint').waypoint(...) Commented May 4, 2016 at 16:43
  • Sorry, I edited my code; I actually load jQuery this way an all the other jQuery scripts are working, so I guess it has nothing to do with it? Thank you anyway, @DaveRoss ! Commented May 4, 2016 at 17:17
  • Are your paths correct? Do the files actually load correctly? Commented May 4, 2016 at 17:47
  • @EatPeanutButter I think they do but don't really know, I'm not a php-wordpress expert, I guess Waypoints.js is working somehow but not properly if I can get the alert fired sometimes when resizing the browser. Commented May 4, 2016 at 17:52

2 Answers 2

0

Waypoints is using $ to access jQuery, but with WordPress you need to refer to jQuery as jQuery.

I found that I had to use the no framework version of Waypoints to get it working with WordPress.

Sign up to request clarification or add additional context in comments.

Comments

0

I got stuck into the same issue for several hours today.

The solution is described - here (same issue on stack).

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.