Skip to content

Set up WordPress wp-cron.php to run manually

By default the WordPress tasks that have been set up to run with wp-cron.php only run when a WordPress page is visited by a user, if the site has low traffic then tasks make take a while to action, if the site is high traffic and has caching then this can also cause reliability issues, instead you can manually set up the cron tasks to run at a timed schedules instead.

Disable default WordPress wp-cron.php

Disable the default WordPress cron behaviour by adding a PHP constant to wp-config.php

define('DISABLE_WP_CRON', true);

Now it won’t run, but you’ll have to now set up a cron job on your hosting platform, below are 2 ways with Cloudways and cPanel.

Set up WordPress cron with Cloudways

Go to Application Management > Cron Job Management > Add New Cron Job

Cloudways Add Cron

 

In the next screen add the location path of the wp-cron.php file and how often you want to run it, my example runs it every 30 mins.

(By setting the cron job up with the Basic tab in Cloudways, the task is automatically run by PHP, whereas in cPanel you need to explicitly add the PHP path. If you swap to the Advanced tab in Cloudways you’ll see the PHP path in full)

Cloudways Add Cron Schedule

 

Set up WordPress cron with cPanel

In cPanel search for Cron and add a new one.

Cpanel Add WordPress Cron

 

Make sure add the correct path to wp-cron.php, also you need to run the file as the PHP user, so set the PHP path prefixing the cron file with a space in between.

Then set a schedule, this example sets a 10min interval, you also have an option of an email alert if you want to make sure the cron has run.

 

Viewing and Running wp-cron.php with WP Crontrol plugin

Wp Cron Control Plugin

WP Crontrol plugin can show you a list of tasks or events that are scheduled to run, you can edit, delete or run the tasks now, this is a good way to troubleshoot events that are stuck or past the time.

Viewing and Running wp-cron.php with WP CLI

With WP CLI installed you can list all events.

wp cron event list

You should see output like…

+-------------------------------------------+---------------------+-----------------------+---------------+
| hook                                      | next_run_gmt        | next_run_relative     | recurrence    |
+-------------------------------------------+---------------------+-----------------------+---------------+
| jetpack_v2_heartbeat                      | 2019-10-17 03:56:45 | now                   | 1 day         |
| action_scheduler_run_queue                | 2019-10-17 04:00:08 | now                   | 1 minute      |
| jetpack_sync_cron                         | 2019-10-17 04:01:42 | now                   | 5 minutes     |
| jetpack_sync_full_cron                    | 2019-10-17 04:01:42 | now                   | 5 minutes     |
| prli_cleanup_visitor_locks_worker         | 2019-10-17 04:16:11 | now                   | 1 hour        |
| jetpack_clean_nonces                      | 2019-10-17 04:23:01 | now                   | 1 hour        |
| wp_privacy_delete_old_export_files        | 2019-10-17 04:39:57 | now                   | 1 hour        |

The tasks or hook names are on the left and the other columns list their run time and frequency

To run all events due now…

wp cron event run --due-now

To run a specific event now, choose the hook name…

wp cron event run jetpack_v2_heartbeat

Remote crons

You can also use remote cron service instead to schedule tasks, one such is https://cron-job.org which is free, there are others and paid solutions too.

That’s it, with WP CLI it makes it easy to troubleshoot and see what is going on and generally setting the cron to run on a set basis makes for better cron allround.

Leave a Comment





Scroll To Top