How to Schedule Cron Jobs with WordPress

How to Schedule Cron Jobs with WordPress

A cron job lets you automatically execute a function at a specific interval – WordPress can do this for you with the wp_schedule_event() function. Here is how you can schedule a hook that will be executed by the WordPress actions core on a specific interval (in this example it will execute the cron job each hour), specified by you. The action will trigger when someone visits your WordPress site if the scheduled time has passed.

Add this code to your functions.php file.

add_action('my_hourly_event', 'do_this_hourly');

          function my_activation() {
	     if ( !wp_next_scheduled( 'my_hourly_event' ) ) {
		wp_schedule_event(time(), 'hourly', 'my_hourly_event');
     add_action('wp', 'my_activation');

     function do_this_hourly() { // do something every hour

WordPress Hosting


Leave a Reply

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