Skip to content

Instantly share code, notes, and snippets.

@Christian-Roth
Last active August 26, 2016 11:15
Show Gist options
  • Save Christian-Roth/df2a67b7886e05ba80b02adf8a9e5760 to your computer and use it in GitHub Desktop.
Save Christian-Roth/df2a67b7886e05ba80b02adf8a9e5760 to your computer and use it in GitHub Desktop.
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