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