WordPress Cron Explained (Real-World Guide After 6 Years)

Published: (June 10, 2026 at 11:57 PM EDT)
3 min read
Source: Dev.to

Source: Dev.to

Email should send every hour → doesn’t Cleanup should run nightly → skips One-time reminder after signup → never fires The code looks fine. Local works. Production doesn’t. After 6 years building WordPress themes, plugins, and WooCommerce projects, I can tell you: most cron issues are not syntax errors. They’re misunderstanding how WordPress scheduling works. A scheduled task is a job WordPress runs later — automatically. Examples: Send reminder emails Clean old logs Sync data to a CRM Fire a one-time follow-up after purchase WordPress calls this system WP Cron. Server cron runs at an exact time (e.g. 3:00 AM daily). WP Cron runs based on traffic.

Site type Behavior

High traffic Reliable

Low traffic Delayed

Staging Unpredictable

Schedule → Hook name → add_action() → Function runs

// Check if already scheduled wp_next_scheduled( $hook, $args );

// Schedule repeating task wp_schedule_event( $timestamp, $recurrence, $hook, $args );

wp_next_scheduled() → check first wp_schedule_event() → schedule add_action() → connect callback add_action( ‘butterfly_hourly_email_hook’, ‘butterfly_send_email_func’ );

function butterfly_create_cron_event() {

$args = [
    'hemal.akanda.39@gmail.com'
];

if ( ! wp_next_scheduled( 'butterfly_hourly_email_hook', $args ) ) {

    wp_schedule_event(
        time(),
        'hourly',
        'butterfly_hourly_email_hook',
        $args
    );
}

}

function butterfly_send_email_func( $email ) {

wp_mail(
    sanitize_email( $email ),
    __( 'Reminder', 'butterfly-cron' ),
    __( 'Hey Butterfly. Its a custom message from butterfly', 'butterfly-cron' )
);

}

add_action( ‘butterfly_single_event_hook’, ‘butterfly_send_email’ );

function schedule_single_event() {

$args = [
    'hemal.akanda.39@gmail.com'
];

if ( ! wp_next_scheduled( 'butterfly_single_event_hook', $args ) ) {

    wp_schedule_single_event(
        time() + 3600,
        'butterfly_single_event_hook',
        $args
    );
}

}

function butterfly_send_email( $email ) {

wp_mail(
    sanitize_email( $email ),
    __( 'Send a email subject', 'butterfly-cron' ),
    __( 'Send email message', 'butterfly-cron' )
);

}

function butterfly_schedule_an_event() { wp_schedule_event( time(), ‘hourly’, ‘butterfly_schedule_an_wp_event’ ); }

add_action( ‘butterfly_schedule_an_wp_event’, ‘butterfly_create_an_wp_event’ );

function butterfly_unschedule_an_event() {

$timestamps = wp_next_scheduled( 'butterfly_schedule_an_wp_event' );

if ( $timestamps ) {
    wp_unschedule_event( $timestamps, 'butterfly_schedule_an_wp_event' );
}

}

function butterfly_create_an_wp_event() {

wp_mail(
    sanitize_email( 'hemal.akanda.39@gmail.com' ),
    __( 'Create a meetup on wordpress in dhaka', 'butterfly-cron' ),
    __( 'Hey! Lets create a meetup for WordPress Community in Dhaka/Bangladesh', 'butterfly-cron' )
);

}

add_filter( ‘cron_schedules’, ‘butterfly_cron_schedule’ );

function butterfly_cron_schedule( $schedules ) {

$schedules['weekly'] = [
    'interval' => 604800,
    'display'  => __( 'Once a week', 'butterfly-cron' )
];

return $schedules;

}

wp_schedule_event( time(), ‘weekly’, ‘my_weekly_hook’ );

$cron = _get_cron_array(); $all_schedules = wp_get_schedules(); ?>

$hooks ) : ?>

 $events ) : ?>

    

        

            
                
            

            
                
            

            
                ``
            

        

    

wp_schedule_event() → repeating task wp_schedule_single_event() → one-time task wp_next_scheduled() → check exists wp_unschedule_event() → remove task cron_schedules → custom intervals No wp_next_scheduled() → duplicates Never unscheduling → ghost jobs Low traffic sites → delayed cron Heavy tasks on page load Missing add_action()

Production tip

define( ‘DISABLE_WP_CRON’, true );

0 views
Back to Blog

Related posts

Read more »

The spec is in the wrong place

My day job is at a large tech company. Hundreds of engineering teams, and every one of them is somewhere different on AI adoption. Some are still treating codin...

The Heuristics Say Don't

A culture that only records its disasters ends up with a biased archive. Wars documented, plagues chronicled, collapses catalogued. The quiet decades go unwritt...