# Countdown to a Launch or Deadline Widget

> Adds a dashboard widget counting down the days and hours to a date you set, such as a site launch, campaign start or content deadline, to keep the whole team focused.

- Type: PHP
- Runs: Admin only
- Category: [Dashboard](https://wpide.com/library/category/dashboard/)
- Tags: dashboard-widget, countdown, deadlines
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/dash-launch-countdown-widget/

## Code

```php
// Target date and time (site time zone) and its label.
$wpide_countdown_date  = '2026-12-01 09:00';
$wpide_countdown_label = 'Website launch';

add_action( 'wp_dashboard_setup', function () use ( $wpide_countdown_date, $wpide_countdown_label ) {
    wp_add_dashboard_widget( 'wpide_launch_countdown', 'Countdown: ' . esc_html( $wpide_countdown_label ), function () use ( $wpide_countdown_date, $wpide_countdown_label ) {
        $target = date_create_immutable( $wpide_countdown_date, wp_timezone() );
        if ( ! $target ) {
            echo '<p>Set a valid date in the snippet.</p>';
            return;
        }

        $left = $target->getTimestamp() - time();
        if ( $left <= 0 ) {
            printf( '<p style="font-size:16px"><strong>%s</strong> was on %s.</p>', esc_html( $wpide_countdown_label ), esc_html( wp_date( get_option( 'date_format' ), $target->getTimestamp() ) ) );
            return;
        }

        $days  = (int) floor( $left / DAY_IN_SECONDS );
        $hours = (int) floor( ( $left % DAY_IN_SECONDS ) / HOUR_IN_SECONDS );

        printf(
            '<div style="text-align:center;padding:10px 0"><div style="font-size:40px;font-weight:700;line-height:1">%d</div><div>days and %d hours until</div><div style="font-size:16px;font-weight:600;margin-top:4px">%s</div><div style="color:#646970">%s</div></div>',
            $days,
            $hours,
            esc_html( $wpide_countdown_label ),
            esc_html( wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $target->getTimestamp() ) )
        );
    } );
} );
```

## Notes

Set the date and time in your site's time zone; after the date passes the widget shows a "done" message.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Countdown to a Launch or Deadline Widget" 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/
