Content Switch Example
USAGE – SINGLE USE
To show or hide content at one point in time, you can use the shortcode. For example:
Please enter our competition
Sorry, this competition has closed
If you do not enter a time with the date, it will default to 00:00:00, so in the above example, the first message will show up until 2015-01-01 00:00:00 (i.e. until the first second of 2015) and the second message will show up from 2015-01-01 00:00:00 (i.e. from the first second of 2015)
You can use any date or time string supported by PHP, such as:
Will show after 09/10/2014 at 6pm
You can also combine starting and ending dates for the same piece of content. So if you want some content to appear between January 1st and January 10th, you could do the following:
USAGE – REPEATING SCHEDULE
To show and hide content on a recurring schedule, you can use the
Note that you can also cross over midnight, so to only show something from 10PM to 5AM, you can use:
For the night owls
A weekly schedule takes the following form:
The work week
You can also specify start and stop times if you want (it will assume starting at 00:00:00 and ending at 23:59:59 if these are left out, like above):
A monthly schedule takes the following form:
You can both cross over the end of the month, and apply times to your start and end dates, e.g.
We are exceptionally busy at the end of each billing cycle. Please bear with us!
And lastly, an annual schedule takes the following form:
You can cross over the end of the month or even the end of the year, and apply times to your start and end dates, e.g.
If you’re feeling creative, you can even nest shortcodes to account for multiple concurrent conditions. Since you cannot nest shortcodes with the same name, you need to add -2 or -3 to time-restrict-repeat in your shortcode (e.g.
You can also define a message which should appear if your content is not showing by using the else attribute @since 2.5. For example, you could invite people to visit your store during opening hours and ask them come back soon otherwise, like this:
We're currently closed. Come back and see us when we're open.