search

Add a Custom WP-Cron Interval in WordPress

WordPress ships with three WP-Cron intervals: hourly, twicedaily, and daily. If you need a different interval (e.g. every 5 minutes), add the following code. For more on WordPress hooks and filters.

add_filter( 'cron_schedules', function( $schedules ) {
	$schedules['every_five_minutes'] = array(
		'interval' => 300,
		'display'  => 'Every 5 Minutes',
	);
	return $schedules;
} );

// Schedule the event on theme activation
if ( ! wp_next_scheduled( 'my_custom_cron_event' ) ) {
	wp_schedule_event( time(), 'every_five_minutes', 'my_custom_cron_event' );
}

add_action( 'my_custom_cron_event', function() {
	// Your code here
} );
Join the Discussion
0 Comments  ]

Leave a Comment

To add code, use the buttons below. For instance, click the PHP button to insert PHP code within the shortcode. If you notice any typos, please let us know!

Savvy WordPress Development official logo