Counting Down The Days

Today, I would like to share with you how to create a WordPress countdown plugin of a future date and time. The plugin output displays the number of days, hours, minutes and seconds left. The plugin uses a WordPress shortcode that you can insert inside your post. A Shortcode makes it easier to display results in WordPress.

Output: [counting_down_the_days]

Here’s the plugin code:

Plugin Name: Counting Down the Days
Plugin URI:
Description: php countdown
Version: 1.0
Author: Ulysses Ronquillo
Author URI:
// place your php code here
function urr_countdown_days() { 
$date = strtotime("January 27, 2017 7:15 PM");
$remaining         = $date - time();
$days_remaining    = floor($remaining / 86400);
$hours_remaining   = floor(($remaining % 86400) / 3600);
$minutes_remaining = floor(($remaining-($days_remaining*60*60*24)-($hours_remaining*60*60))/60);
$seconds_remaining = floor(($remaining-($days_remaining*60*60*24)-($hours_remaining*60*60))-($minutes_remaining*60));
return 'There are '.$days_remaining.' days and '.$hours_remaining.' hours and '.$minutes_remaining.' minutes and '.$seconds_remaining.' seconds left.';

The PHP date function is used to calculate the days, hours, minutes and seconds remaining and returns the output. The script is one of many PHP examples online on how to perform countdowns. This was one of the more popular ones. The script also uses the PHP floor function to get the lowest integer while ignoring the leftover fraction or remainder. To use the plugin, place the shortcode ‘counting_down_the_days’ (wrap it in square brackets) anywhere inside your WordPress post.

Output: [counting_down_the_days]

If you set a date in the past, the output will say, “Set a future date!”

Install PHP on Mac

This article will show you how to install PHP on the Mac. By default, Apache and PHP are already installed on the Mac, although both are not activated. We must first enable Apache. Once you’ve Apache is enabled, you can then proceed in activating PHP.

This article is part of a series of articles on how to manually install Apache, PHP, MySQL on the Mac OS. Installing the popular MAMP application is as simple as installing any other application on the Mac, but it will not give you any valuable learning experience, nor will you have complete control of your development environment. I recommend manually installing the individual applications to maximize your learning experience.

How to Install PHP on Mac OS X

PHP is already installed. We just have to enable it. Edit the ‘/etc/apache2/httpd.conf‘ file.

$ sudo nano /etc/apache2/httpd.conf

Uncomment or delete the ‘#’ sign for the line that contains the text below.

LoadModule php5_module libexec/apache2/

Restart Apache

$ sudo apachectl restart

Place a index.php file that contains the following in your web server root.

<?php phpinfo(); ?>

If you see PHP info and stats, that means PHP is working! If you see the code, it means PHP is not working.