I originally posted this in the stackoverflow, but I believe it is better posted here as I am using wordpress and a wordpress function. I am trying to add the jquery cycle plugin (http://jquery.malsup.com/cycle/) to my wordpress site, so I enqueued it in my functions.php, and then added a script right before the /body tag. When I load the page, I get the error in the console: Uncaught TypeError: $(...).cycle is not a function. When I open the source file, the cycle plugin script is also not there. I am not sure what I am doing incorrectly.

To break down what I did, I downloaded the jquery.cycle.all.js file and put in in my child theme (lets call it TestChild) in the directory like so TestChild/assets/scripts/jquery.cycle.all.js. I then declared the wp_enqueue_script function in my functions.php. I then added the script before my /body tag. I would appreciate any help as this has been causing me hours of frustration.

This is my code:

    function theme_add_cycle_slide (){
       wp_enqueue_script('cycleall', get_stylesheet_directory_uri() . '/assets/scripts/jquery.cycle.all.js', array ('jquery'), null, true);
    add_action ('wp_enqueue_script', 'theme_add_cycle_slide' );

    <div id="slideshow">
      <div style="width:250px; height:150px; background:red;"></div>
      <div style="width:250px; height:150px; background:blue;"></div>
      <div style="width:250px; height:150px; background:green;"></div>
      <div style="width:250px; height:150px; background:yellow;"></div>
        <div id="prev" style="float:left;">PREV</div>
        <div id="next" style="float:right;">NEXT</div>

     <script language="javascript">
    jQuery(document).ready(function($) {
        fx:    'fade',
        pause:  1
  • Ok, I fixed one thing finally. For the function, in add _action it should be 'wp_enqueue_scripts' not 'wp_enqueue_script'. Now I have another error. [cycle] terminating; zero elements found by selector – LearntoExcel Jun 22 '16 at 2:58

Problem was a simple misspelling.

The add_action should be

add_action ('wp_enqueue_scripts', 'theme_add_cycle_slide' );

I wrote 'script'


Try This one :

  wp_register_script('cycleall', plugins_url('/assets/scripts/jquery.cycle.all.js', __FILE__), array('jquery'),'1.1', true);

change script to scripts in add_action() should be

add_action ('wp_enqueue_scripts', 'theme_add_cycle_slide' );
  • nope get_template_directory_uri() will give the path for parent theme not the child – terminator Jun 22 '16 at 4:31
  • yeah you are right – user93819 Jun 22 '16 at 4:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.