Version 2.0.0: Peter’s Date Countdown Plugin for WordPress

First published on February 3, 2007

The Olympics are here!

After I posted about php code for countdowns, a couple of people asked me to implement it into their WordPress installation. However, for ease of management of countdown items, I decided to simply make a WordPress plugin for it. I’ve seen a few similar plugins already available, but none of them seem to have a user-friendly management page.

Here’s a screenshot of the management page in the WordPress admin section:

Admin screenshot of Peter's Date Countdown for WordPress

Here’s a screenshot of the output in a sidebar:

Sidebar screenshot of Peter's Date Countdown for WordPress

To install the plugin:

Unzip all files to a “peters-date-countdown” subdirectory in your WordPress plugin directory. The download link is below.

Activate it in the Plugins menu of your admin section. There are a few settings at the top of the plugin file to tweak several features (for example, you can enable the new JavaScript real-time countdown feature), so you should edit that as well.

Then, paste this code wherever you wish to display the countdowns:


Starting from version 1.6 onwards, if you want to call a specific countdown, enter the number of the countdown item that you want to display in parentheses, such as this:


If you want to put the countdowns on your sidebar, here’s the code for most themes (paste this in sidebar.php):

<?php countdown_callit(); ?>

Alternatively, you can use the plugin as a WordPress widget (see the “Design… Widgets” page).

You can then add, delete, and update countdown items on the “Manage… Date Countdown” page of your admin section.

If you are upgrading, make sure that you do NOT overwrite datecountdowndates.php! Also, make sure that the files are placed in the folder “wp-content/plugins/peters-date-countdown”

Peter’s Date Countdown Plugin for WordPress Version 2.0.0 -August 25, 2008: Finally combined the widget and non-widget versions of this plugin into one version.

Download site 1 | Download site 2

View all past versions


Countdowns in use:

Leah’s Ponderwonderments

Incongruous Balderdash


New support forum, which is better for organizing questions and comments:

Forum/Topic Started Last post Posts

44 Responses to “Version 2.0.0: Peter’s Date Countdown Plugin for WordPress”

  1. Leah says:

    I love it! Go visit my website and see my countdowns!

  2. Julia says:

    I love it too!

    Great skill Peter!

  3. nate says:

    im getting errors with your script. when i try to add a date to the count down… if you could email me, i’ll reply back with the errors im getting. i’d greatly apprieciate it.

  4. Peter says:

    Update: I got in contact with Nate. Seems to be a permissions error. Not only does the datecountdowndates.php file need to be writable, but your user / group needs to have write permission.

    If you’re getting errors similar to below, ask your server admin to check the permissions on the users / groups:

    Warning: fopen(../path/to/blah): failed to open stream: Permission denied in path/to/blah on line X

    Warning: fwrite(): supplied argument is not a valid stream resource in /path/to/blah on line X

  5. cricket says:

    Great plugin!

    I have a stupid question, though. (sorry!)

    “Not only does the datecountdowndates.php file need to be writable, but your user / group needs to have write permission.”

    Um…forever? In other words, do I just leave those permissions turned on indefinitely?

    Thanks muchly :)

  6. Peter says:

    A stupid question it is not! Yes — that file always needs to be writable because the script will always be interacting with it to update the countdown items.

  7. nat says:

    Hey, heres a request. could you make it so that the sooner it gets it turns into counting down hours, and then minutes?

  8. Peter says:

    Good idea, Nat. This would be a slightly more involved tweak… I’ll see what I can do when I have the time!

  9. Jim says:

    Then, paste this code wherever you wish to display the countdowns:

    How do I get the above code into a post when I use the html editor it always changes the above code. Or is it not possible to run from insde a post?

  10. Peter says:

    To use PHP code inside a post, you’ll have to install a plugin similar to this one:

    By default, WordPress doesn’t allow any PHP code inside posts…

  11. Old Cat says:

    Hi, I have added in some functionalities to this plugin… If you are interested to include them in the next release, please contact :)

    In admin panel, the user can input a time till which the ‘finished’ text will be displayed. And when a visitor points cursor over the item in the countdown list, a tip will show up displaying the time of the event. Just some tiny little codes :)

    I am using widgets now, so I made it into a widget too.

  12. Richard Bui says:

    How do you customize it to say something else besides sleeps? Great plugin, BTW! Thanks!

  13. Vishwas says:

    I don’t know if this is the right place for a feature request, but your plugin works great. I’d like to see a count-up feature in some future versions. Just an Idea though.

    Currently I’m using

    a script (coded by someone else) to have a count-up function. for. e.g. : XX days since “some event occured” + your widget for countdown XX days before “some event happens”

    It’d be really nice if you could add this count-up feature in the next version of your plugin. I

  14. tkearsey says:


    great plugin. just a quick question. how do i allow my “editors” have access to the manage option to create countdowns? right now it’s only available to my admin account. thanks.

  15. tkearsey says:

    Thanks for your help Peter! I’ll post your reply here for others:

    You’ll have to edit the plugin and scroll down to this piece of code:

    function datecountdown_adminmenu(){
    add_management_page(‘Date Countdown’, ‘Date Countdown’, 9, ‘datecountdown.php’, ‘countdown_manage’);

    That 9 refers to administrator accounts. Setting it to ‘7’ should give your editors access.

    Worked for me perfectly.

  16. John Boyd says:

    Great plugin, works like a charm. Thanks for keeping it updated!

  17. Stoffel says:

    I’m using your plugin for quite a while, and discovered today that there’s a realtime java version. Cool! I just installed it, and played with it for a while. Everything works great, except there’s one glitch that I don’t like. When using the Java version, it starts counting negative numbers after an event has passed. I’m not very technical, so I don’t know if there’s an easy/quick/dirty way to make the java version act like the ‘normal’ version so that a text line is shown after an event has passed? Thanks for the plugin!

  18. Dave says:

    Peter – version 1.9 worked like a charm, and the countdown timer is working properly on all my pages. Thanks for being so responsive!

  19. cyberlussi says:

    Very nice and smooth … I’d like to see a revision within you can easily change language by setting only a bunch of variables. That would be even greater!

  20. Avi says:

    Is it possible to change the date format to EST instead of GMT?

  21. Peter says:

    Yes — there is a setting at the top of the plugin file to set the time zone:

    // Change this if you want to add or subtract hours from your server time
    $timediff = 0;

  22. Tati says:

    How I can change of number of events to apear in my sidebar?

  23. Peter says:

    // Change this to equal the maximum number of countdowns to display at once. For an unlimited number of countdowns, make it equal 0
    $numcountdowns = 0;

  24. Thomas Durka says:


    how can i set the target for the links as “_blank” instead of “_self”?

    With regards.

  25. Peter says:

    This will take some tweaking of the plugin file in three places:

    Here (this piece of code appears twice):

    // show link if there is one
    if ($link <> "") {
    print "<a href=\"$link\">";

    Change the print line to:
    print "<a href=\"$link\" target=\"_blank\">";


    // display link if desired
    if ($link <> "") {
    print "href=\"$link\" ";

    Change the print line to:
    print "href=\"$link\" target=\"_blank\" ";

  26. Rex says:

    got this:

    Warning: fopen(../wp-content/plugins/datecountdown/datecountdowndates.php) [function.fopen]: failed to open stream: Permission denied in /home/sports/public_html/fightcountdown/wp-content/plugins/datecountdown/datecountdown.php on line 224

    Warning: fwrite(): supplied argument is not a valid stream resource in /home/sports/public_html/fightcountdown/wp-content/plugins/datecountdown/datecountdown.php on line 225

    Warning: fclose(): supplied argument is not a valid stream resource in /home/sports/public_html/fightcountdown/wp-content/plugins/datecountdown/datecountdown.php on line 226

  27. Peter says:

    Did you make sure that datecountdowndates.php is writable (777 permissions)?

  28. ed says:

    Hi Peter! just wondering if you can help me? I need the coundown for the number of users registered on my website. How do I change the code to look at the wordpress code for the number of registered users? instead of the time?

    Thank you.


  29. Peter says:

    Hi ed,

    I don’t think what you’re suggesting is really a countdown, but rather a simple display of the user count?

    You can show the number of users by putting this code somewhere in your template (maybe the sidebar or footer):

    <?php print $wpdb->get_var('SELECT COUNT(*) FROM ' . $wpdb->users); ?>

    For more detailed statistics, check out this plugin or this plugin .

  30. Leon says:

    Hi Peter – your script looks very good.

    Is it possible to link a count down event to a post? Ie – ‘ X more sleep to the Olympics’ and when clicked will take you to Olympics post.

    Cheers – Leon.

  31. Peter says:

    Yes, there is a field for a link when you go to Manage > Date Countdown.

  32. no says:

    Could you please put widget capabilities into the normal plugin? WordPress wants me to upgrade 1.93w to plain old 1.93.

  33. Peter says:

    Yup, I’ve finally merged that into one plugin with version 2.0.0.

  34. Vzx says:

    Hi Peter

    Nice work on merging the plugin and widget into a single file. I’ve just got one more issue – every time I upgrade, the date countdowns and options are reset.

    I believe this is because all the information is saved in the php files which get overwritten with every upgrade. Is there a way by which user created info is saved on the DB? this would preserve all the dates and option in b/w upgrades.

  35. Peter says:

    Hi Vzx, thanks for the suggestion. I originally put the countdown items in a file because I didn’t want to add even more database calls every time a page is loaded. When I get around to it, I’ll look into perhaps storing the countdown items (and options) in a database but making a cache file from the database.

    In the meantime, just make sure to copy what’s in datecountdowndates.php!

  36. Callow says:


    really like your widget. It’s nice with the sleeps.
    On my website I don’t want it with a caption, are there any options to delete this out of the sourcetext?

  37. Peter says:

    Hi Callow, yes you can remove the caption by removing the code that displays the "title" tag.

    Replace this:
    print "title=\"$dc_datedisplay (GMT $dc_gmtdiff)\">";

    With this:
    print ">";

  38. Ed B. says:

    Hey Pete! Thanks for the countdown timer. Been looking for a simple one for a while.

    I have an idea in the event you plan on continued development.

    An auto delete function. For each event for example. Delete this event after xx days of completion?

    What can I say? I’m lazy!! Thanks again for the time you put in to this widget.

  39. RC says:

    Is there a way to set it up so that the countdown prefaces it with a date. For example. there’s a countdown widget out there that displays like this:

    Nov 1 – Event Name (123 Days)

    Ideally I’d like to see it where the widget says:

    Nov 1: 23 more sleeps until Event Name

    Just curious… awesome plugin,


  40. Peter says:

    Hi RC, at the moment I have no short term plans for new versions of this plugin. However, all of the display logic is handled in the "countdown_execute" function in the plugin file, which you can certainly modify to your liking.

  41. derhenry says:

    Hey, good job!
    It works fine. But: The number of sleeps isn’t correct, if you’re living in germany. Like I do. What can I do? :o)

    Reply from Peter: Did you set the time zone in the plugin file to be relative to your server time? Also, if you want true “sleep” counting, like midnight-to-midnight, see this post.

  42. jeff says:

    I have this as a widget but the days are displaying wrong I don’t this its 78 more days to Sept 25th

    Reply from Peter: The plugin calculates the number of days relative to the server time, so your server time might be a bit off. However, I see from your site that the count is displaying correctly now :)

  43. Pavel says:

    Hey Piter, grat job!
    Best countdown plugin around!!

    Quick question:
    I’m using <?php countdown_callit(); ?> method to display your countdown and I was wondering if i can also "print" the variable of the date of the countdown (i only have one) close to the callit function.

    Is there a variable to print? Something like <?php print $date_variable; ?>

    Thank for the adnvice and compliments for the great job.


    Reply from Peter: There is no global variable for that, but you could include the datecountdowndates.php file and then access $importantdate[0][1] for the month; [0][2] for the day, [0][3] for the year; [0][5] for the hour; and [0][6] for the minute.

  44. Roger says:

    Hi, is there any way to customize the look (font, style, color etc.) of the widget?

    Reply from Peter: Yes, if you edit line 512 of the plugin to add a class to the list container, you can then style it as needed via CSS.

    Example for line 512:
    echo $before_title . $pdc_widget_header . $after_title . ‘<ul class="date-countdown">';

Speak your mind

To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word