It's often necessary to provide some sort of countdown to an event in WordPress - particularly in the marketing world where we're often scheduling webcasts, live tutorials, and other edutainment. While we plan to provide about a dozen different countdown options, the first is the second most basic (the simplest is another scheduled post titled "Static Day Countdown with WordPress Shortcode or PHP"). Subsequent articles integrate existing countdown libraries for a very fancy rendering.
To count down to Sydney's 2025 New Years Eve, we'll use the shortcode of
[countdown date="31st December 2025 11.59:59pm"]. The result:
With a little bit of style we can make it look a little more appealing.
Copy and paste the WordPress function into your theme's
functions.php file or, if you sensibly have one installed, your custom functions plugin. You may optionally download and install our plugin from the bottom of of the page.
textis the string that is rendered once the expiry time has passed.
styleto the countdown text, the style is applied to the span.
date="31st December 2017 11.59:59pm"for our example, but something like
date="20171231235959"would work as well. Date values separated by slash are assumed to be in American order: m/d/y, and those separated by dash are assumed to be in European order: d-m-y.
offset="10". For a negative offset, use a minus sign.
- For a fixed event, a fixed UTC offset will obviously apply. For the same event in different timezones (such as New Years Eve), you might consider obtaining the offset via our API and applying that in your code.
- For this simple countdown, the intent is that it'll be used once on each page. Using multiple occurrences will produce erroneous results. Our future examples don't suffer the same limitation.