Skip to content

Instantly share code, notes, and snippets.

@ben-heath
Created August 31, 2018 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ben-heath/4e689641d2c7fc193acb5e221ce6a0d1 to your computer and use it in GitHub Desktop.
Save ben-heath/4e689641d2c7fc193acb5e221ce6a0d1 to your computer and use it in GitHub Desktop.
WordPress Shortcode countdown clock using FlipClock.js
<?php
/* Need to include flipclock.js's css and js files. Instructions found on their github page
* http://flipclockjs.com
*
*/
// Flipper countdown function
function sls_flipper_countdown($atts){
// Attributes - For the End Date
extract( shortcode_atts(
array(
'end_date' => '',
'end_time' => '',
), $atts )
);
// code
ob_start();
$output = '
<p class="countdown-timer"></p>
<script src="/flipclock/compiled/flipclock.min.js"></script>
<script type="text/javascript">
var countDownDate = new Date("'.esc_attr($end_date).' '.esc_attr($end_time).'").getTime();
var now = new Date().getTime();
// Find the distance between now and the count down date
var distance = countDownDate/1000 - now/1000;
var clock = jQuery(\'.countdown-timer\').FlipClock(distance, {
clockFace: \'DailyCounter\',
countdown: true,
showSeconds: false
});
</script>
';
$output .= ob_get_contents();
ob_end_clean();
return $output;
}
add_shortcode('course-countdown','sls_flipper_countdown');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment