Via the Webs

Current PHP Date & Time

How to Use

Download > Install > Activate.

Insert shortcode [[lwdatetime 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 [[lwdatetime display=”© Y”]] to get [lwdatetime display=”© Y”]

Multiple Formats in One Shortcode
Inserting shortcode [[lwdatetime 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 [lwdatetime display=”F jS”]

Multiple Formats in One Shortcode with Text
Inserting shortcode [[lwdatetime 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 [lwdatetime display=”h:i:s A”]

Avoid Conflicting Text
Inserting shortcode [[lwdatetime 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 [[lwdatetime display=”z”]] day of [[lwdatetime display=”o”]]. would output Today is the [lwdatetime display=”z”] day of [lwdatetime 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.

/*
Plugin Name: Lightweight Plugins - Current PHP Date Time 
Plugin URI: https://lightweightplugins.com/plugin/current-php-date-time/
Description: A lightweight plugin that provides shortcodes for the current, Year, Month, Day, Time and more.
Version: 3.2
Author: WP Maintenance Experts
Author URI: https://wpmaintenanceexperts.com/
License: GPLv2 or later
*/

function build_lighweight_plugins_cpdt_shortcode( $atts ){
        $args = shortcode_atts(array(
    'display' => 'Y',
    ), $atts);
        $d = $args["display"];
  return date($d);
}
add_shortcode( 'lwdatetime', 'build_lighweight_plugins_cpdt_shortcode');

Plugins Articles

Disable XML-RPC

Disabling XML-RPC in WordPress can be beneficial for several reasons: Security Concerns: XML-RPC has been targeted by attackers in various types of malicious activities: Brute Force Attacks: Attackers can use XML-RPC to amplify their brute force attacks. Instead of...

read more

MS Clarity Exclude Logged In Users

How to Use Download > Install > Activate. Use your favorite IDE or just edit within the WordPress plugin editor. Change "xxxxxxxxxx" to be your Clarity ID. Not associated with Microsoft® Clarity® Example This prevented me from recording all my logged in back-end...

read more

Add to Console Log

How to Use Download > Install > Activate. Use your favorite IDE or just edit within the WordPress plugin editor. Change the message to suit your needs. Example A fun project plugin. Thought of this after discovering a software company had a message about their open...

read more

Most Recent Articles