I have the following code to execute cron job in every 3 hours to display time in the head.But it didn't work.
register_activation_hook( __FILE__, 'wpce_prefix_activation' );
function wpce_prefix_activation() {
wp_schedule_event( current_time ( 'timestamp' ), 10800, 'prefix_three_hourly_event_hook' );
}
add_action( 'prefix_three_hourly_event_hook', 'wpce_prefix_do_this_three_hourly' );
function wpce_prefix_do_this_three_hourly() {
// do something every hour
add_action('wp_head', 'add_link_in_head');
} // end function
function add_link_in_head(){
echo time();
}//end of function
register_deactivation_hook( __FILE__, 'wpce_prefix_deactivation' );
function wpce_prefix_deactivation() {
wp_clear_scheduled_hook( 'prefix_three_hourly_event_hook' );
}
add_filter( 'cron_schedules', 'filter_cron_schedules' );
// add custom time to cron
function filter_cron_schedules( $schedules ) {
$schedules['fively'] = array(
'interval' => 300,
'display' => __('Once in Five minutes')
);
$schedules['in_per_minute'] = array(
'interval' => 60,
'display' => __('In every minute')
);
$schedules['in_per_ten_minute'] = array(
'interval' => 600,
'display' => __('Once in Ten minutes')
);
$schedules['1_hours'] = array(
'interval' => 3600,
'display' => __('Hour')
);
$schedules['three_hourly'] = array(
'interval' => 10800,
'display' => __('Once in three hours')
);
return $schedules;
}
I want to run the cron job in wordpress every 3 hours,5 hours,6 and 7 hours.
If anyone can help it would really appreciate. Thank you