Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Functions to add a custom WP cron
function your_function(){
// **** Add your function here ****
}
add_action( 'your_cron_action', 'your_function' );
// Init Cron Job
function init_custom_cron() {
if( !wp_next_scheduled( 'your_cron_action' ) ){
wp_schedule_event( time(), '20min', 'your_cron_action' );
}
}
add_action('init', 'init_custom_cron');
// Add custom schedule for Cron Jobs
function custom_cron_schedules($schedules){
if( !isset($schedules['20min']) ){
$schedules['20min'] = array(
'interval' => 20*60,
'display' => __('Once every 20 minutes')
);
}
return $schedules;
}
add_filter('cron_schedules','custom_cron_schedules');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment