Cron Job WordPress (WP-Cron)

Code

Cron Job WordPress (WP-Cron)

What Is WordPress Cron Job?

WordPress Cron Job is how WordPress handles scheduling time-based tasks in WordPress.“Cron” Means the cron time-based task scheduling system which is available on UNIX systems.

A WordPress CRON job is a task or action which is scheduled to run automatically at specific intervals. To simplify scheduling tasks, WordPress Cron Scheduling three default intervals and very easy method for adding custom intervals.
The default intervals provided by WordPress are:

  • hourly
  • twicedaily
  • daily

For adding a custom interval, you can use filter.
Example custom cron schedule for every 10 Seconds & 10 days.


function CustomCronScheduler( $schedules ) {
  if(!isset($schedules['10sec'])){
    $schedules['10sec'] = array(
      'display' => __( 'Every 10 Seconds'),
      'interval' => 10,
    );
  }
  if(!isset($schedules['after10days'])){
    $schedules['after10days'] = array(
      'display' => __( 'Once in 10 days'),
      'interval' => 10*DAY_IN_SECONDS,
    );
  }
  return $schedules;
}
add_filter(‘cron_schedules’,‘CustomCronScheduler’ );
wp_schedule_event( int $timestamp, string $recurrence, string $hook, array $args = array() );

wp_schedule_event function Schedules a hook which will be triggered by WordPress at the specified interval. The action will trigger when someone visits your WordPress site if the scheduled time has passed.


if (!wp_next_scheduled('TenDaysCronHook')) {
  wp_schedule_event (time (), "after10days", 'TenDaysCronHook') ;
}
if (!wp_next_scheduled ('TensecCronHook')) {
  wp_schedule_event (time (), "10sec", 'TensecCronHook') ;
}

function TenDaysCronFunction (){
  //action u want to perform in every 10 days.
}
add_action ('TenDaysCronHook','TenDaysCronFunction') ;

function TensecCronFunction (){
  //action u want to perform in every 10 sec.
}
add_action ('TensecCronHook','TensecCronFunction') ;

Enjoy

Shiv kumawat

Executive Director & CEO

"Shiv kumawat is the Executive Director and CEO of Eoxys It Solution LLP and the strategic mind behind the company"s growth. His expertise in operational efficiency and team leadership empowers his colleagues to excel and innovate.”

Latest Posts

Seeds of Innovation: How AI is Redefining American Agriculture in 2025

  Seeds of Innovation: How AI is Redefining American Agriculture in 2025 Planting the Future with Artificial Intelligence In 2025,…

Shafeeq Khan
September 11, 2025

Building the Future: AI Innovations and Essential Features for Healthcare Apps in 2025

  Building the Future: AI Innovations and Essential Features for Healthcare Apps in 2025 The Dawn of Intelligent Health Apps…

Shafeeq Khan
September 10, 2025

When Machines Heal: Exploring the New Frontier of AI in Mental Health Care

  When Machines Heal: Exploring the New Frontier of AI in Mental Health Care Technology Steps Into Compassion In the…

Shafeeq Khan
September 9, 2025
, , ,

Leave a Reply

Your email address will not be published. Required fields are marked *