So what sort of things could you use Expiry for? Well straight away it is ideal to display important messages or special promotions before or after a certain date. Typically many of us want things to start or end at midnight, but being available to update a website manually at midnight is not always an option. So Expiry can help automate the display of content at particular times. As the name suggests, it can also be used to hide blocks of content (like events or products) after a certain date or time. It's certainly a stack with plenty of uses.

If you require a more advanced set of stacks for hiding and showing content at particular times, take a closer look at the AdvancedPublisher stacks.


Here are some basic examples of the Expiry stack in action:
This Expiry stack was setup to display content at any time before 25th December 2020. So if you are looking at this page before this date, you should be reading this content right now!
This Expiry stack was setup to display content after 4th July 2013. So if you are looking at this page after this date, you should be reading this content right now!


To use the Expiry stack, please follow these instructions in this order:

  1. Set the time zone in the stack settings. This can be used to offset your server time; for example if your website is hosted in another country, you can set the Expiry stack to your local timezone without needing to mess-around with the server php.ini file. If you are not sure what to enter in this box, refer to for a list of supported timezones.
  2. Set the time / date setting to the point at which you want active content to hide and expired content to display. We use the PHP mktime function in this stack, so the time and date you provide needs to be entered in hours,minutes,seconds,month,day,year format. So for an expiry date of 16th April 2014, you would need to enter 0,0,0,4,16,2014 in the box.
  3. In the stack settings, select from the Display menu whether the content should display before or after the expiry date and time is reached or exceeded.
  4. Drag and drop stacks into the expired content and / or active content boxes. Both are optional, so if you prefer you can omit content from either the expired or active placeholders - useful if you simply want to hide content after a certain date and display nothing in its place.
  5. Make sure that this page has a .php file extension set in the RapidWeaver Page Inspector. The Expiry stack will try to do this for you automatically, but you should check this setting anyway and refrain from changing it back to another file extension.
Remember - this is a stack that uses PHP code. It will only work on a live web server with a standard (and active) installation of PHP 5.2 or later. It may not always work correctly in RapidWeaver preview, on cheapo web hosts or web servers running a substandard or incomplete version of PHP.

Source Code

This is the source code used to create each Expiry stack.

<?php if(time() < mktime(0,0,0,10,31,2013)) { ?>
	<h2>Hurry - the sale ends on 31st October 2013!</h2>
<?php } ?>

The 'less-than' bracket can be replaced with a 'more-than' bracket if you want the content to display after the date and time. Basically all we're doing here is some conditional logic that takes the current date/time from the web server and compares it with the mktime string you set. If the conditional logic returns true, then the content is displayed. If the conditional logic returns false, the content will get removed.

@import((Code Snippets))


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.