# 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.

- Type: PHP
- Runs: Run everywhere
- Category: [Content](https://wpide.com/library/category/content/)
- Tags: shortcode, schedule, dates
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/scheduled-content-shortcode/

## Code

```php
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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Show Content Between Two Dates" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
