Home / functions.php / Countdown timer shortcode, display content after specified date
  • How to Countdown timer shortcode, display content after specified date


    Adding the first snippet to the functions.php of your wordpress theme will let you use a shortcode to place a countdown timer on specific content within your post. Add the shortcode within the second snippet to your post with content you want to display after the specified date. I added a class of event so you can style the display of the message anyway you wish, enjoy!

    wordpress snippet : PHP

    function content_countdown($atts, $content = null){
         '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=\"event\">Just <b>($remain)</b> days until content is available</div>";
        }else if($remain == 1 ){
    	return $daysremain = "<div class=\"event\">Just <b>($remain)</b> day until content is available</div>";
            return $content;
    add_shortcode('cdt', 'content_countdown');

    wordpress snippet : SHORTCODE

    [cdt month="10" day="17" year="2011"]
    This is content that will only be shown after a set number of days.

    ( WordPress codex functions, hooks, in this snippet. )

    add_shortcode, shortcode_atts,
  • Matt


    Great piece of code :)

    Is there a way to remove the content on a set date? So you can set the date to show the content and it can expire on a set date?


    • http://wpsnipp.com Kevin Chard

      Hi Matt I’m sure we can do something like that Ill post a snippet in the near future.

      • Matt

        Thanks Kevin :)