How To Make a Countdown Timer Shortcode to Display Content After Date

Snippets by IsItWP

Are you looking for a way to make a countdown timer shortcode to display content after a specific date? This snippet will make a shortcode that places a countdown timer on specific content within your post. The content will only be visible after the specified date.


  1. Add this code to your theme’s functions.php file or in a site-specific plugin.
  2. 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');
  3. Add this shortcode to your post with the content you want to display after the specified date. Don’t forget to set the date attributes as well.
  4. [cdt month="11" day="15" year="2020"]
    This is content that will only be shown after a set number of days.

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: CSS Hero Review: #1 WordPress Theme Customization Plugin.

Comments   Leave a Reply

  1. Jesus Rico Vargas February 28, 2019 at 2:20 am

    How to apply this code but to create for Minutos but not Days?

  2. wickandcoilchurch August 15, 2015 at 2:36 pm

    How can we make this loop as I wish to have a button at the end instead of text. Once the button is clicked it does said action related to the button and simply shows timer again. If user is not logged in it shall simply show the button until he/she logs in and clicks on it.

  3. Hey,

    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?


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

      1. Thanks Kevin 🙂

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!