Skip to content

Instantly share code, notes, and snippets.

@nfsarmento
Created September 13, 2021 10:49
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 nfsarmento/8793df6d5a0e57c17d9f7c930168f894 to your computer and use it in GitHub Desktop.
Save nfsarmento/8793df6d5a0e57c17d9f7c930168f894 to your computer and use it in GitHub Desktop.
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