Created
August 31, 2018 14:15
-
-
Save ben-heath/4e689641d2c7fc193acb5e221ce6a0d1 to your computer and use it in GitHub Desktop.
WordPress Shortcode countdown clock using FlipClock.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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