For cron jobs, WordPress comes with a few built-in schedules to add your event to – hourly, twicedaily, daily and (since WordPress 5.4) weekly. All of them run on a defined interval. Hourly runs every hour, twicedaily runs every 12 hours, daily runs every 24 hours and weekly runs every 7 days. To add a new schedule time, the cron_schedules filter is used. The code below will add three new cron schedules ( in_per_minute, in_per_ten_minute, three_hourly ).
Add Custom Schedules
add_filter( 'cron_schedules', 'w4dev_cron_schedules');
function w4dev_cron_schedules( $schedules )
{
$schedules['in_per_minute'] = array(
'interval' => 60,
'display' => 'In Every Minute'
);
$schedules['in_per_ten_minute'] = array(
'interval' => 60 * 10,
'display' => 'In Every Ten Minutes'
);
$schedules['three_hourly'] = array(
'interval' => 60 * 60 * 3,
'display' => 'Once in Three Hours'
);
return $schedules;
}
Reference: interval is measured in seconds. 2 minutes = 60 * 2 sec. display is the display label name for the schedule. Note that we add our schedules to the $schedules array instead of returning a new array, otherwise we would remove schedules registered by other plugins.
Using the new schedule
First you will need to register an event for the schedule. You can register multiple events for one schedule. Upon registering an event with a schedule, a new action hook becomes available.
Schedule an Event
if( !wp_next_scheduled('w4dev_one_minute_event') )
{
wp_schedule_event( time(), 'in_per_minute', 'w4dev_one_minute_event' );
}
This code will schedule a new event w4dev_one_minute_event to be run every minute. That means, each minute, an action hook – w4dev_one_minute_event will be available once to call.
Call a function on scheduled event
You can hook into the event with your function. You can even hook multiple times using multiple functions.
function w4dev_one_minute_job_cron()
{
// your code here
}
add_action( 'w4dev_one_minute_event', 'w4dev_one_minute_job_cron' );
That’s it. All of the above code can be placed in your theme’s functions.php file or in a plugin.

Leave a Reply