The Elementor widget
With Elementor, it is very easy to display the date of a publication with the Post Information widget.
Date and time fields in the Elementor interface
To display the date and time the publication was created, two fields are generated. One for the date, the other for the time.
In the date field you can choose the ‘Custom‘ format. This allows us to enter the personalization code (see table below).
For the time field, it’s the same.
Change the date and time of a publication
To change the date and time of a publication, this is done on the WordPress interface. Select a publication to edit, then change its date and time.
Change the date and time of the last publication’s modification
This option was not provided by WordPress. It may seem logical not to be able to do so for obvious reasons of security and confidentiality. Imagine if someone could edit a post and then change the date and time of the edit so that it is not visible that an edit has been made.
But there are cases where you want to do it anyway. I take as an example, a publication that needs to be moved to another site. You export the publication and then import it to the other site. We then change a few lines to adapt to the design of the new site. The modification date changes, but the publication was written several years ago. It’s strange to see a publication date of 2010 and its last modification date in 2020.
How to change the date and time with a plugin
There are several plugins available. Here is the one I tested. It comes with settings options, but it works without touching it.
How to change the date and time without a plugin
If you are allergic to plugins, you can modify this data directly in the WordPress database with SQL. I give you the simplest query. There are certainly other solutions. This one works with mySQL and certainly with all other SQL engines.
It is a question of retrieving the ID of your publication by giving its slug as an argument. This one must of course be unique. Then change the date of modification and its GMT value.
It is advisable to have some SQL experience before you start doing this. A false query could cause indelible damage to your site.
To make this query work, you must of course connect to your database, and then
- Change the wp_prefix_posts with your prefix number.
- Change the year-month-day hour:minute:second with a real date that could look like this: 2020-12-16 20:30:00
- Change the slug with your argument for the publication to be modified.
UPDATE wp_prefix_posts
SET post_modified = 'year-month-day hour:minute:second', post_modified_gmt = 'year-month-day hour:minute:second'
WHERE ID IN (SELECT * FROM (SELECT ID FROM wp_prefix_posts WHERE post_name LIKE '%slug%') as t);
Table of customization codes for date and time
I will finish this publication by publishing a table of codes that can be inserted, for example, in the Post Information Widget in Elementor.
- d – The day of the month (from 01 to 31)
- D – A shortened textual representation of the day (Mon, Tue, …)
- j – The day of the month without the zero (1 to 31)
- l – The day in all letters (Monday, Tuesday, …)
- N – The ISO-8601 numeric code of the day (1 for Monday, 2 for Tuesday, …)
- S – The English ordinal suffix for the day of the month (2 characters st, nd, rd or th. Works correctly with j)
- w – A numerical representation of the day (0 for Sunday, 6 for Saturday, …)
- z – The day in the year (from 0 to 365)
- W – The ISO-8601 numeric code of the week in the year (weeks start on a Monday)
- F – A full month’s representation (January to December)
- m – A numerical representation of one month (from 01 to 12)
- M – A shortened text representation of the month (Jan, Feb, Tue, …)
- n – A numerical representation of a month without the zero (1 to 12)
- t – The number of days in the current month
- L – Determine if it is a leap year (1 for leap year, 0 in other cases)
- o – The ISO-8601 code of the year
- Y – A four-digit representation of the year
- y – A two-digit representation of the year
- a – am or pm in lower case
- A – AM or PM in upper case
- B – Internet time (000 to 999)
- g – 12-hour format for one hour (1 to 12)
- G – 24-hour format for one hour (0 to 23)
- h – 12 hour format for one hour with the zero (01 to 12)
- H – 24 hour format for one hour with zero (00 to 23)
- i – Minutes with zero (00 to 59)
- s – Seconds with zero (00 to 59)
- u – Microseconds (added since PHP 5.2.2)
- e – Time zone ID (Examples: UTC, GMT, Atlantic/Azores)
- I – (capital I), Determine if the date is in daylight saving time (1 if daylight saving time, 0 in other cases)
- O – Difference with Greenwich Mean Time (GMT) in hours (Example: +0100)
- P – Difference with Greenwich Mean Time (GMT) in hours:minutes (added since PHP 5.1.3)
- T – Time zone abbreviations (Examples: EST, MDT)
- Z – The time zone shift in seconds. The offset for the western time zone of UTC is negative (-43200 to 50400).
- c – The ISO-8601 code for the date (e.g. 2013-05-05T16:34:42+00:00)
- r – The date in RFC 2822 format (e.g. Fri, 12 Apr 2013 12:01:05 +0200)
- U – Seconds since the Unix era (January 1 1970 00:00:00 GMT)