Skip to content

WordPress custom cron schedules and intervals code

WordPress custom cron schedules and intervals

By default, WordPress only supports the intervals 'hourly', 'twicedaily', and 'daily' . What if we want our cron job to run at intervals other than the default? It is quite simple actually, we just have to hook cron_schedules

add_filter( 'cron_schedules', 'custom_cron_schedules' );
function custom_cron_schedules( $schedules ) 
{
    $schedules['every-1-minute'] = array(
        'interval' => MINUTE_IN_SECONDS, // Every 1 Minute
        'display'  => __( 'Every 1 Minute' ),		
    );
    
    $schedules['every-1-hour'] = array(
        'interval' => HOUR_IN_SECONDS * 1, // Every 6 hours
        'display'  => __( 'Every 1 Hour' ),
    );
    
    $schedules['every-6-hour'] = array(
        'interval' => HOUR_IN_SECONDS * 6, // Every 6 hours
        'display'  => __( 'Every 6 Hours' ),
    );
    
        
    return $schedules;
}

 

Enjoyed the content ? Share it with your friends !
Published inDevelopmentProgramming

Be First to Comment

Leave a Reply

Your email address will not be published.