Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WordPress Countdown Timer Shortcode
<?php
/*
*
* Countdown Timer Shortcode
* [cdt month="9" day="28" year="2021"] This is content that will only be shown after a set number of days.[/cdt]
*
*/
// @codingStandardsIgnoreStart
function aet_content_countdown($atts, $content = null){
extract(shortcode_atts(array(
'month' => '',
'day' => '',
'year' => ''
), $atts));
$remain = ceil((mktime( 0,0,0,(int)$month,(int)$day,(int)$year) - time())/86400);
if( $remain > 1 ){
return $daysremain = "<div class=\"sitelunch\"><h4>Countdown to launch!</h4><span class=\"sitelunchdays\">$remain</span><h4>days</h4></div>";
}else if($remain == 1 ){
return $daysremain = "<div class=\"sitelunch\"><h4>Countdown to launch!</h4><span class=\"sitelunchdays\">$remain</span><h4>day</h4></div>";
}else{
return $content;
}
}
add_shortcode('cdt', 'aet_content_countdown');
// @codingStandardsIgnoreEnd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment