Halloween Sale 15% off Ends in See the plans
PHP

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.

Don’t have WPIDE yet? Install it on your site

Code

// 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 add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.