12% off of LTD using this coupon: TWELVEPERCENTOFF. Promo ends on 2 Dec midnight UTC.
Published on Feb 25, 2021

[Condition] Date and time

Sridhar Katakam

This members-only tutorial provides the steps to register a custom condition using which elements in Oxygen can be set to be output before, after or at a specified date or date and time.

The date and time is to be entered in this format: Y-m-d H:i:s.

Ex.: 2021-03-25 16:30:00

With the above (per screenshot) set for a Section, it will be output only after the 25th of March 2021 4:30 pm in the timezone set in WordPress settings.

Note: It is recommended to select a city for Timezone rather than a UTC offset.

If time is omitted, it will be taken as midnight (12am).

Even though Oxygen has built-in Date and Time conditions, as of Oxygen 3.7 they do not use the Date/Time improvements added in WordPress 5.3.

This condition uses the recommended function, current_datetime() and the recommended approach, DateTimeImmutable class.

Also, the built-in Date condition shows the placeholder as MM/DD/YYYY when it should be Y-m-d. Date entered in MM/DD/YYYY format in the built-in Date condition will not work.

Step 1

Install and activate Code Snippets plugin.

Go to Snippets > Add New.

Title: [Condition] Date and time

Code:

This is a premium members-only content.

To view the rest of the content, please sign up for membership ($47/month or $599 one-time).

Already a member? Log in below or here.

tagschevron-leftchevron-rightchainangle-rightangle-upangle-downfolder-omagnifiercrossmenuchevron-downarrow-right