How to Use
Download > Install > Activate.
Insert shortcode [[vwdatetime display=”parameter(s)”]], replacing parameter(s) with the desired output from the PHP date & time parameters below. Non-parameter characters will be rendered as it.
Date Parameters
d – Day of the month, 2 digits with leading zeros, example 01 to 31
D – A text representation of a day, three letters, example Mon through Sun
j – Day of the month without leading zeros, example 1 to 31
l – (lowercase ‘L’) A full text representation of the day of the week, example Sunday through Saturday
S – English suffix for the day of the month, 2 characters, example st, nd, rd or th.
w – Numeric representation of the day of the week, example 0 (for Sunday) through 6 (for Saturday)
z – The day of the year (starting from 0), example 0 through 365
Week Parameters
W – Week number of year, weeks starting on Monday, example 42 (the 42nd week in the year)
Year Parameters
L – Whether it’s a leap year, example 1 if it is a leap year, 0 otherwise.
Y – A four digit representation of a year, example 2004
y – A two digit representation of a year, example 04
Time Parameters
a – Lowercase Ante meridiem and Post meridiem, example am or pm
A – Uppercase Ante meridiem and Post meridiem, example AM or PM
g – 12-hour format of an hour without leading zeros, example 1 through 12
G – 24-hour format of an hour without leading zeros, example 0 through 23
h – 12-hour format of an hour with leading zeros, example 01 through 12
H – 24-hour format of an hour with leading zeros, example 00 through 23
i – Minutes with leading zeros, example 00 to 59
s – Seconds, with leading zeros, example 00 through 59
Timezone Parameters
e – Timezone identifier, example UTC, GMT, Atlantic/Azores
I – (capital i)Whether or not the date is in daylight saving time, example 1 if Daylight Saving Time, 0 otherwise.
O – Difference to Greenwich time (GMT) in hours, example +0200
P – Difference to Greenwich time (GMT) with colon, example +02:00
T – Timezone abbreviation, example EST, MDT
Full Date/Time Parameters
c – ISO 8601 formatted date, example 2004-02-12T15:19:21+00:00
r – RFC 2822 formatted date, examlpe Thu, 21 Dec 2000 16:01:07 +0200
U – Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT), example
Example
Copyright © Year
Insert shortcode [[vwdatetime display=”© Y”]] to get [vwdatetime display=”© Y”]
Multiple Formats in One Shortcode
Inserting shortcode [[vwdatetime display=”F jS”]] would output F (full text of the month), then a space, then j (day of the month – no zero), then S (day of the month suffix). Example –> Today is [vwdatetime display=”F jS”]
Multiple Formats in One Shortcode with Text
Inserting shortcode [[vwdatetime display=”h:i:s A”]] would output hour:minute:second space capital AM/PM. The colons output as the character they are since they are not a parameter. Example –> The time is [vwdatetime display=”h:i:s A”]
Avoid Conflicting Text
Inserting shortcode [[vwdatetime display=”Today is the z day of o.”]] would output gibberish since some of the letters are also recognized parameters. To achieve this you would use two shortcodes. Example –> Today is the [[vwdatetime display=”z”]] day of [[vwdatetime display=”o”]]. would output Today is the [vwdatetime display=”z”] day of [vwdatetime display=”o”].
Source
This code can be pasted into the functions.php file of your child theme or, download and install the plugin for simple code activation.
function build_viawebs_plugins_cpdt_shortcode( $atts ){
$args = shortcode_atts(array(
'display' => 'Y',
), $atts);
$d = $args["display"];
return date($d);
}
add_shortcode( 'vwdatetime', 'build_viawebs_plugins_cpdt_shortcode');