WP Manifestindependent plugin directory
manifest / utilities / wp-current-time

WP Current Time

A WordPress plugin to display the current time and/or date with a WordPress shortcode [current-time] or [current-date]

by Greg Rickaby · github.com/gregrickaby/wp-current-time · website

3stars
0forks

Install

No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:

wp plugin install https://github.com/gregrickaby/wp-current-time/archive/refs/heads/master.zip

Readme

WP Current Time

Display the current time and/or date with a WordPress shortcode [current-time] or [current-date]. Compatible with Gutenberg, the Classic Editor, and Widgets.

Table of Contents

Installation

  1. Download this plugin
  2. Upload/Add this plugin via the WordPress plugins dashboard
  3. Activate the WP Current Time plugin

Note: This plugin requires PHP 5.3+

Basic Usage

This plugin creates two shortcodes which can be placed into Gutenberg, the Classic Editor, or a text widget.

[current-time]

Will display the current time in 12-hour format: 01:00:00

[current-date]

Will display the current date in month/day/year format: 10/19/2018

The basic shortcodes use your web server's time. If you need to customize your time zone, see Advanced Usage

Advanced Usage

Shortcodes

[current-time format="H:i:s" timezone="America/Chicago"]

Will display the current time, in 24-hour format, based on the central time zone: 13:00:00

[current-date format="d/m/Y" timezone="America/New_York"]

Will display the current date, based on the eastern time zone: 19/10/2018

To see the full list of time zones, check out official PHP documentation: https://secure.php.net/manual/en/timezones.php

Multiple Shortcodes

You can also daisy chain these shortcodes together, for example:

[current-time format="H:" timezone="America/Chicago"]
[current-time format="i:" timezone="America/Chicago"]
[current-time format="s" timezone="America/Chicago"]

would output: 14:00:00 based on the central time zone.

Custom HTML

You can even write your own HTML and CSS in the WordPress text editor:

<time class="hour">[current-time format="H:" timezone="America/Chicago"]</time>
<time class="minutes">[current-time format="i:" timezone="America/Chicago"]</time>
<time class="seconds">[current-time format="s" timezone="America/Chicago"]</time>

would output:

<time class="hour">14:</time>
<time class="minutes">00:</time>
<time class="seconds">00</time>

Template Tag

You could even use the following template tags inside your theme:

if ( function_exists( 'wpct\current_time' ) ) {
    echo wpct\current_time( array(
        'format'   => 'H:i:s',
        'timezone' => 'America/Chicago'
    ) );
}

would output: 13:00:00

if ( function_exists( 'wpct\current_date' ) ) {
    echo wpct\current_date( array(
        'format'   => 'm/d/Y',
        'timezone' => 'America/Chicago'
    ) );
}

would output: 10/19/2018

Date/Time Format Characters

PHP has several characters available for changing how the format of date and time is displayed. For example:

m/d/Y = 10/19/2018

d-m-Y = 19-10-2018

Common Format Characters

Character Description Returned Value
d Day of the month, 2 digits with leading zeros 01 to 31
D A textual representation of a day, three letters Mon through Sun
l A full textual representation of the day of the week Sunday through Saturday
m Numeric representation of a month, with leading zeros 01 through 12
M A short textual representation of a month, three letters Jan through Dec
F A full textual representation of a month, such as January or March January through December
y A two digit representation of a year Examples: 99 or 03
Y A full numeric representation of a year, 4 digits Examples: 1999 or 2003
h 12-hour format of an hour with leading zeros 01 through 12
H 24-hour format of an hour with leading zeros 00 through 23
i Minutes with leading zeros 00 to 59
s Seconds, with leading zeros 00 through 59
U Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) 1539961739

To see the full list of characters, check out official PHP documentation: https://secure.php.net/manual/en/function.date.php

Style Notes

The styles are minimal on purpose. There are a two CSS classes available:

.current-time

.current-date

For more control, see: Custom HTML

Usage examples

Gutenberg example
Classic editor example
Widget example

Made with :heart: and lots of :coffee: by Greg Rickaby.

Read the full README on GitHub →