[How to] Add a Countdown to Post or Page Using Shortcode
I added shortcode functionality to the WordPress Countdown Widget with version 2.4. Using this new update, you can add countdown timers to your posts and pages easily. In this post, I am explaining how to use the shortcode feature.
Basic Syntax
Basic shortcode syntax:
[countdown event="Testing shortcode" date="1 June 2021"]
This shortcode displays:
Wow, that’s a lot of numbers! But don’t worry, We can limit digits using the countdown widget format option 😉
See Also
Default Syntax
Let’s add hours & minutes to this:
[countdown event="Event with hour & minutes" date="1 June 2021" hour="18" minutes="54"] :
Please note that hours are 24 hours based. If you write 6 pm there, it won’t work.
Shortcode Attributes
Here is a list of default shortcode attributes:
$args = shortcode_atts(array( 'title'=>'', 'event'=>'', 'date'=>false, 'month'=>'', 'day'=>'', 'hour'=>'0', 'minutes'=>'0', 'seconds'=>'0', 'year'=>'', 'format'=>'yowdHMS', 'link'=>false ), $atts );
Note: If you use the date field, you don’t need to specify day, month and year. Those are automatically calculated via magic date attribute.
Full Syntax
And here is the full shortcode template in case you need it:
[countdown title="Countdown" event="Until next release" date="1 June 2021" hour="13" minutes="45" seconds="00" format="DHMS"]
For shortcode displays, you can’t define background color and color values. Those can only be changed via CSS. For styling tips read my tutorial here.
Conclusion
I hope you found this tutorial useful. Get latest version of countdown widget.