user18577
user18577

Reputation: 643

Correct way to include jquery scripts in Wordpress?

I am using the following jquery script in a Wordpress site. It works fine when I do not enqueue jQuery. However, when jQuery is enqueued, it no longer runs.

Any ideas what I am doing wrong?

$(function() {

    var $sidebar   = $(".side"), 
        $window    = $(window),
        offset     = $sidebar.offset(),
        topPadding = 15;

    $window.scroll(function() {
        if ($window.scrollTop() >= 240) {
            $sidebar.stop().animate({
                marginTop: $window.scrollTop() - offset.top + topPadding
            });
        } else {
            $sidebar.stop().animate({
                marginTop: 0
            });
        }
    });

});

PS. Yes, I have tried changing the intial call from $(function)) to jquery(function)) but it still does not run.

Upvotes: 0

Views: 87

Answers (1)

Christian
Christian

Reputation: 19740

You need to pass the $ symbol to the function: jQuery(function($){ }) so you can use it within your code. Otherwise you need to replace every $ in your code with jQuery

See: jQuery.noConflict()

Upvotes: 1

Related Questions