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

AI in Healthcare USA Transforming Patient Care and Operations in 2025

  AI in Healthcare USA: Transforming Patient Care and Operations in 2025 The Rise of AI in Healthcare Across the…

sakshi
August 7, 2025

AI in Restaurants: How Artificial Intelligence Is Revolutionizing the Food Service Industry

  AI in Restaurants: How Artificial Intelligence IsRevolutionizing the Food Service Industry Introduction: The Digital Transformation of Dining Restaurants around…

sakshi
August 6, 2025

Artificial Intelligence in Mobile App Development: The Complete 2025 Guide

  Artificial Intelligence in Mobile App Development:The Complete 2025 Guide Introduction: Why AI is Now Central to Mobile App Innovation…

sakshi
August 6, 2025
, , ,

Leave a Reply

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