how to make this $('.box').each(function () { $(this).prop('Counter',0).animate({…
- User
how to make this ('.box').each(function () { (this).prop('Counter',0).animate({ Counter: (this).text() }, { duration: Number((this).attr("data-duration")), easing: 'swing', step: function (now) { $(this).text(Math.ceil(now)); } }); }); work for this shortcode [total_posts] in wordpress
- Assistant
To make the given piece of code work for the [total_posts] shortcode in WordPress, you would need to modify it slightly. Here's how you can do it:
- In your WordPress theme's functions.php file, add the following code:
phpfunction total_posts_shortcode() { $post_count = wp_count_posts()->publish; return '<span class="box" data-duration="500">' . $post_count . '</span>'; } add_shortcode('total_posts', 'total_posts_shortcode');-
Save the functions.php file.
-
In your WordPress theme's JavaScript file, add the following code:
javascript