Show Content Between Two Dates
Adds a [scheduled] shortcode that shows the text inside it only from a start date, until an end date, or between both. Ideal for limited offers and event notices.
Opens WPIDE on
Code
add_shortcode( 'scheduled', function ( $atts, $content = '' ) {
$atts = shortcode_atts( array( 'from' => '', 'until' => '' ), $atts, 'scheduled' );
$now = time();
if ( '' !== $atts['from'] ) {
$from = date_create( $atts['from'], wp_timezone() );
if ( $from && $now < $from->getTimestamp() ) {
return '';
}
}
if ( '' !== $atts['until'] ) {
$until = date_create( $atts['until'], wp_timezone() );
if ( $until && $now > $until->getTimestamp() ) {
return '';
}
}
return do_shortcode( (string) $content );
} );
Notes
Example: [scheduled from="2026-11-25 00:00" until="2026-11-30 23:59"]Black Friday sale![/scheduled]. Dates use the site time zone. Page caching may delay the switch.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.