Although RapidWeaver has a %last_updated% macro, the format of the presented date and time cannot be changed. The LastUpdated stack uses some modern PHP code to ascertain when the webpage last got updated (derived from its file modification date). Using this stack, you have almost complete freedom of the date / time format displayed and even the ability to adjust it for specific timezones. This is a huge upgrade over the basic functionality of the %last_updated% macro in RapidWeaver.

Another impressive feature in LastUpdated is the ability to alert a website user if content has changed on a webpage, since their last visit. This feature uses harmless tracking cookies to record and store the date / time of the last visit. Then a PHP conditional statement to test this against the date / time the page was last modified. If the user comes back to the page after an update, a custom message can be shown to them. See the details below.

Example

This is the LastUpdated stack using its default settings. As you can see, all styling and fonts are inherited from the theme, for great consistency. Prefixes and suffixes are supported too.
Page last updated: 30 January 2023 at 9:14am

Setup

Using LastUpdated is simple.
  1. Download and install the stack, in the normal way.
  2. Open your Stacks Library and search for 'LastUpdated'.
  3. Drag and drop a copy of the stack into your page.
  4. With the stack selected in edit mode, you can customise its settings.
  5. For the date and time formats, please refer to this website, for the correct parameters to use.
  6. Preview the page to check it the stack is working. You may need to preview twice to get the correct date and time to show*.
  7. Save your changes. Export or publish the page in the normal way.

*The first time you preview the page in RapidWeaver, it may incorrectly display the last updated date and time as 1st January 1970. After you preview the page a second time, the correct date and time should be shown. This is due to the way RapidWeaver constructs pages dynamically for the live preview, and deletes them again when you close RapidWeaver.

Also of note, the LastUpdated stack uses PHP code. It will attempt to change the page extension to .php in the Page Inspector automatically. If the same page was previously published with a .html extension, you may need to manually delete the old page via FTP. This extension change has no impact on page loading speeds or SEO, if you're already using tidied links.

LastUpdated is compatible with Stacks v4. You are able to set it as a partial, for the ease and convenience of quickly adding it to multiple pages of a website, like within a site footer. LastUpdated will display the date and time individually for each page of the website.

Alert visitors to changes

This works by setting a tracking cookie on the users computer, set to the current date and time, that the page was accessed. If the time the page was updated is newer than the cookie, an alert can be shown to the user. You could simply inform the user that the page has updated since their last visit and for them to clear their cache or perform some other action on the page, like checking an events calendar or scrolling to view some important content etc.

You can see the cookie being generated in the web inspector. The cookie is unique to each page of your website. Its name is in the format of pageID_last_updated so you know what it is. The time value is set in UNIX Epoch format.

Please note that this function does not work reliably in RapidWeaver preview. It is best to export or publish your page to test it fully. Cookies are set for a maximum of 90 days, although some web browsers may delete the cookie after only 7 days.
 

Contribute

If you find this stack element useful in your personal or commercial web projects; please consider making a small contribution towards ongoing support and updates. There are many different ways you can contribute to the Stacks4Stacks project, and benefits for doing so.