Andrew Nevins
(@anevins)
WCLDN 2018 Contributor | Volunteer support
See this article on using JavaScript in WordPress http://codex.wordpress.org/Using_Javascript
noConflict wrappers would look like this http://jsfiddle.net/nQjPE/12/
So this is what the code should look like in WordPress?
<html>
<head>
<title>JavaScript Replace</title>
<script language="JavaScript1.1" type="text/javascript">
var START_DATE = new Date("October 21, 2012 22:30:00"); // put in the starting date here
var INTERVAL = 1; // refresh interval in seconds
var INCREMENT = 769.2; // increase per tick (1/0.0013 ~ 769)
var START_VALUE = 35000; // initial value when it's the start date
var count = 0;
jQuery(document).ready(function($) {
var msInterval = INTERVAL * 1000;
var now = new Date();
count = parseInt((now - START_DATE)/msInterval,10) * INCREMENT + START_VALUE;
$('#counter').html(count.toFixed(0));
window.setInterval( function(){
count += INCREMENT;
$('#counter').html(count.toFixed(0));
}, msInterval);
});
</script>
</head>
<body>
<div id="counter"></div> Network Users
</body>
</html>
[Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]
Andrew Nevins
(@anevins)
WCLDN 2018 Contributor | Volunteer support
Hey Andrew Nevins,
I’ve been reading more about enqueue-ing and just have a few questions as to the process.
I first put my JS file in the js folder.
Then I add this code to the Functions.php folder:
function meal_counter_js () {
wp_enqueue_script(‘meal_counter’, get_template_directory_uri() . ‘js/counter.js’, array(‘jquery’), ‘1.0’, false);
} // End meal_counter_js()
Then how do I call upon the code on a specific page?
Thank you for all your help!
If you have enqueued the script correctly (and it sounds like you have), it will now be available on all pages on your WordPress site.
Thanks for the speedy response,
Do I use add_action(‘wp_print_scripts’, ‘meal_counter_js’, 1); within the page’s content to call on the script?
Do you want the script on all pages of your site? Or just a specific page?
Is this a static Page or a Post?
Esmi! Andrew! I got it to work!!
I simply added <div id="counter"></div> Network Users
inside the page. Perfect! Thanks!