Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$(...).counterUp is not a function WordPress

Unsure why $(...).counterUp is not a function.

  • Waypoints is enqueued after Counter-up.
  • WP core JQuery is loaded before both of them.

View source ordering:

<script type='text/javascript' src='http://testsite.com/wp-includes/js/jquery/jquery.js?ver=1.12.4-wp'></script>
<script type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/Counter-Up/1.0.0/jquery.counterup.min.js?ver=5.2.3'></script>
<script type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/waypoints/4.0.1/jquery.waypoints.js?ver=5.2.3'></script>

How I'm enqueuing Waypoints and CounterUp:

wp_enqueue_script( 'counterup', 'https://cdnjs.cloudflare.com/ajax/libs/Counter-Up/1.0.0/jquery.counterup.min.js', array(), false, false);
wp_enqueue_script( 'waypoints', 'https://cdnjs.cloudflare.com/ajax/libs/waypoints/4.0.1/jquery.waypoints.js', array(), false, false);

JS being used:

jQuery(document).ready(function($) {
    $('.counter').counterUp({
        delay: 10,
        time: 1000
    });
});

What am I missing here?

Edit:

Screenshots of where files are loaded:

enter image description here enter image description here

Have also tried pulling counterup via node_modules:

wp_enqueue_script( 'counterup', plugin_dir_url( __FILE__ ) . 'node_modules/counterup/jquery.counterup.min.js' );

... Still get the same error message.

like image 412
Freddy Avatar asked Nov 07 '22 13:11

Freddy


1 Answers

  1. Download jquery.counterup.min.js and include in your active theme folder/js.

  2. Add below the script in functions.php file.

    function counterup_scripts() 
    {
         wp_enqueue_script('counterup', get_stylesheet_directory_uri() . '/js/jquery.counterup.min.js', array(), false, false);
    
    }
    add_action('wp_enqueue_scripts', 'counterup_scripts');
    
like image 107
Vel Avatar answered Nov 12 '22 12:11

Vel