Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lightSlider is not a function, wordpress

I'm trying to add lightslider(http://sachinchoolur.github.io/lightslider/index.html) in WordPress but I got error

Uncaught TypeError: jQuery(...).lightSlider is not a function(anonymous function) @ (index):99m.Callbacks.j @ jquery.js?ver=1.11.2:2m.Callbacks.k.fireWith @ jquery.js?ver=1.11.2:2m.extend.ready @ jquery.js?ver=1.11.2:2J @ jquery.js?ver=1.11.2:2

I'm trying with the simplest example from their website

HTML

<ul id="lightSlider">
  <li>
      <h3>First Slide</h3>
      <p>Lorem ipsum Cupidatat quis pariatur anim.</p>
  </li>
  <li>
      <h3>Second Slide</h3>
      <p>Lorem ipsum Excepteur amet adipisicing fugiat velit nisi.</p>
  </li>
  <li>
      <h3>Third Slide</h3>
      <p>Lorem ipsum Excepteur amet adipisicing fugiat velit nisi.</p>
  </li>

</ul>

JavaScript

<script type="text/javascript">
//Also tried to add noConflict() function
//jQuery.noConflict();
jQuery(document).ready(function() {
jQuery("#lightSlider").lightSlider(); 

});
</script>

Can somebody help me? Thank you!

like image 858
snoopy_15 Avatar asked Sep 28 '22 06:09

snoopy_15


2 Answers

I resolved problem. The problem exist because somehow jQuery were loaded after lightSlider.js . I don't know how this happened, I just put jQuery to load first in wp_enqueue_script(), before anything else (before css, too) and lightslider.js at the end.

I hope this answer will help someone more. Thank you for help.

like image 86
snoopy_15 Avatar answered Sep 30 '22 11:09

snoopy_15


I had the same problem but I have fixed it. Just copy the entire code of lightslider.js and past it into:

$(document).ready(function(){
   //code of lightslider 

});
like image 28
Cristian Michel Avatar answered Sep 30 '22 11:09

Cristian Michel